Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何生成易趣OAuth用户令牌?_Php_Ebay Api_Ebay Sdk - Fatal编程技术网

Php 如何生成易趣OAuth用户令牌?

Php 如何生成易趣OAuth用户令牌?,php,ebay-api,ebay-sdk,Php,Ebay Api,Ebay Sdk,我一直在使用David Sadler提供的这个来生成对Ebay API的交易调用,但首先我必须创建OAuthUserToken 我使用了gettoken.php示例并创建了以下代码: $service = new \DTS\eBaySDK\OAuth\Services\OAuthService([ 'credentials' => config('ebay.'.config('ebay.mode').'.credentials'), 'ruNam

我一直在使用David Sadler提供的这个来生成对Ebay API的交易调用,但首先我必须创建OAuthUserToken

我使用了gettoken.php示例并创建了以下代码:

    $service = new \DTS\eBaySDK\OAuth\Services\OAuthService([
        'credentials'   => config('ebay.'.config('ebay.mode').'.credentials'),
        'ruName' => config('ebay.'.config('ebay.mode').'.ruName'),
        'sandbox'     => true
    ]);

    $token = session('????'); //here I have to retrieve the authorization callback information.
    /**
     * Create the request object.
     */
    $request = new \DTS\eBaySDK\OAuth\Types\GetUserTokenRestRequest();
    $request->code = $token;
    /**
     * Send the request.
     */
    $response = $service->getUserToken($request);
由于某些原因,我无法为UserOauth令牌生成重定向。我想代码是:

$service = new\DTS\eBaySDK\OAuth\Services\OAuthService([
…自动生成重定向到易趣授权区域,但实际情况并非如此


有人知道如何解决这个问题吗?我想知道如何授予用户访问权限,然后执行调用(例如,
getEbayTime
)。

您可以使用
redirectUrlForUser()
函数生成用于重定向的URL

$url =  $service->redirectUrlForUser([
    'state' => '<state>',
    'scope' => [
        'https://api.ebay.com/oauth/api_scope/sell.account',
        'https://api.ebay.com/oauth/api_scope/sell.inventory'
    ]
]);
之后,当用户从易趣网站返回时,您的代币应存储在
$\u GET[“code”]

$token = $_GET["code"];
因此,您可以发送请求并使用该示例取回OAuth令牌

$request = new \DTS\eBaySDK\OAuth\Types\GetUserTokenRestRequest();
$request->code = $token;

$response = $service->getUserToken($request);

// Output the result of calling the service operation.
printf("\nStatus Code: %s\n\n", $response->getStatusCode());
if ($response->getStatusCode() !== 200) {
    // Display information that an error has happened
    printf(
        "%s: %s\n\n",
        $response->error,
        $response->error_description
    );
} else {
    // Use the token to make calls to ebay services or store it.
    printf(
        "%s\n%s\n%s\n%s\n\n",
        $response->access_token,
        $response->token_type,
        $response->expires_in,
        $response->refresh_token
    );
}
您的OAuth令牌将位于
$response->access\u token
变量中。令牌是短期的,因此如果您想使用它,您需要不时续订它。为此,请使用
$response->refresh\u token
并调用
$service->refreshUserToken()

$response=$service->refreshUserToken(新类型\RefreshUserTokenRestRequest([
'刷新\u令牌'=>'',
“范围”=>[
'https://api.ebay.com/oauth/api_scope/sell.account',
'https://api.ebay.com/oauth/api_scope/sell.inventory'
]
]));
//当您获得第一个OAuth令牌时,以与上面相同的方式处理它

$token=$\u GET[“code”];在您的应用程序中不使用example@s_h更新了我的答案。这基本上就是你在问题中所拥有的。
$request = new \DTS\eBaySDK\OAuth\Types\GetUserTokenRestRequest();
$request->code = $token;

$response = $service->getUserToken($request);

// Output the result of calling the service operation.
printf("\nStatus Code: %s\n\n", $response->getStatusCode());
if ($response->getStatusCode() !== 200) {
    // Display information that an error has happened
    printf(
        "%s: %s\n\n",
        $response->error,
        $response->error_description
    );
} else {
    // Use the token to make calls to ebay services or store it.
    printf(
        "%s\n%s\n%s\n%s\n\n",
        $response->access_token,
        $response->token_type,
        $response->expires_in,
        $response->refresh_token
    );
}
$response = $service->refreshUserToken(new Types\RefreshUserTokenRestRequest([
    'refresh_token' => '<REFRESH TOKEN>',
    'scope' => [
        'https://api.ebay.com/oauth/api_scope/sell.account',
        'https://api.ebay.com/oauth/api_scope/sell.inventory'
    ]
]));
// Handle it the same way as above, when you got the first OAuth token