快速书籍创建客户OAuth 2.0令牌错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了快速书籍创建客户OAuth 2.0令牌错误相关的知识,希望对你有一定的参考价值。

    use QuickBooksOnlineAPIDataServiceDataService; 
    use QuickBooksOnlineAPICoreHttpSerializationXmlObjectSerializer; 
    use QuickBooksOnlineAPIFacadesCustomer; 
    use QuickBooksOnlineAPICoreOAuthOAuth2OAuth2LoginHelper;

    $oauth2LoginHelper = new OAuth2LoginHelper("clientId","clientSecret");
    $accessTokenObj = $oauth2LoginHelper->refreshAccessTokenWithRefreshToken("Q02i05iXG98OaKON8coU5fKmUCuzEkESkpkbXUcViPVnXaJ1eK");
    $accessTokenValue = $accessTokenObj->getAccessToken();
    $refreshTokenValue = $accessTokenObj->getRefreshToken();

    // Prep Data Services
    $dataService = DataService::Configure(array(
        'auth_mode' => 'oauth2',
        'ClientID' => "ClientID",
        'ClientSecret' => "ClientSecret",
        'accessTokenKey' => $accessTokenValue,
        'refreshTokenKey' => $refreshTokenValue,
        'QBORealmID' => "3644364364363463634",
        'baseUrl' => "sandbox-quickbooks.api.intuit.com"
    ));
    $dataService->setLogLocation("/Users/hlu2/Desktop/newFolderForLog");
    $dataService->throwExceptionOnError(true);
    //Add a new Vendor
    $theResourceObj = Customer::create([
        "BillAddr" => [
            "Line1" => $clientInformation['clientHomeAddress'],
            "City" => "t43",
            "Country" => "43t3",
            "CountrySubDivisionCode" => "34tt334",
            "PostalCode" => ""
        ],
        "Notes" => "3t34t",
        "Title" => "34t434t",
        "GivenName" => $clientName[0],
        "MiddleName" => "rehhhreherher",
        "FamilyName" => $clientName[1],
        "Suffix" => "Jr",
        "FullyQualifiedName" => $clientInformation['clientName'],
        "CompanyName" => "43t334t",
        "DisplayName" => $clientInformation['clientName'],
        "PrimaryPhone" => [
            "FreeFormNumber" => $clientInformation['clientPhoneNumber']
        ],
        "PrimaryEmailAddr" => [
            "Address" => $clientInformation['clientEmail']
        ]
    ]);
    $resultingObj = $dataService->Add($theResourceObj);
    $error = $dataService->getLastError();
    if ($error) {
        echo "The Status code is: " . $error->getHttpStatusCode() . "
";
        echo "The Helper message is: " . $error->getOAuthHelperError() . "
";
        echo "The Response message is: " . $error->getResponseBody() . "
";
    }
    else {
        echo "Created Id={$resultingObj->Id}. Reconstructed response body:

";
        $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
        echo $xmlBody . "
";

        return $resultingObj->Id;
    }

我收到这个错误

php致命错误:未捕获QuickBooksOnline API Exception ServiceException:Http状态代码[400]:刷新OAuth 2使用刷新令牌的访问令牌失败。正文:[{“error”:“invalid_grant”}]。 n n在/var/www/project1/vendor/quickbooks/v3-php-sdk/src/Core/OAuth/OAuth2/OAuth2LoginHelper.php中投放在线271,referer:http://project1.local/trial/

我究竟做错了什么。谢谢。

答案
  • 首先,您首先手动生成刷新令牌和accessstoken。
  • 因为第一次获取刷新令牌和访问令牌需要auth代码。
  • 因此,您必须在生成刷新令牌和accessstoken之后生成authcode
  • 在那之后你可以尝试它工作正常

注意:如果您获得无效授权,则必须在生成了accesstoken和referesh令牌后生成authcode

以上是关于快速书籍创建客户OAuth 2.0令牌错误的主要内容,如果未能解决你的问题,请参考以下文章

OAuth 2.0

OAuth 2.0

OAuth 2.0

Spring Boot OAuth 2.0 客户端

OAuth 2.0 的四种授权模式

OAuth 2.0 刷新令牌多个选项卡