【问题标题】:eBay OAuth cannot fetch tokeneBay OAuth 无法获取令牌
【发布时间】:2018-09-18 07:05:13
【问题描述】:

我正在尝试集成 GitHub 中由 David Sadler 开发的 an eBay SDK。但我被困在连接部分本身。我正在使用我的生产凭据获取带有http://localhost/ebay-sdk-examples/oauth-tokens/01-get-app-token.php 的应用令牌。

但是当我点击时,http://localhost/ebay-sdk-examples/oauth-tokens/02-get-user-token.php 它给了我这个错误:

      [error] => invalid_grant
      [error_description] => the provided authorization grant code is invalid or was issued to another client

所有代码均在 SDK 链接中提供。如果您需要这里是代码 sn-p

    <?php
    /**
     * Copyright 2017 David T. Sadler
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */

    /**
     * Include the SDK by using the autoloader from Composer.
     */
    require __DIR__ . '/../vendor/autoload.php';

    /**
     * Include the configuration values.
     *
     * Ensure that you have edited the configuration.php file
     * to include your application keys.
     */
    $config = require __DIR__ . '/../configuration.php';

    /**
     * The namespaces provided by the SDK.
     */
    use \DTS\eBaySDK\OAuth\Services;
    use \DTS\eBaySDK\OAuth\Types;

    /**
     * Create the service object.
     */
    $service = new Services\OAuthService([
        'credentials' => $config['production']['credentials'],
        'ruName' => $config['production']['ruName'],
        'sandbox' => false,
    ]);
    $token = $config['production']['testToken']; ** This is the app token I get with  http://localhost/ebay-sdk-examples/oauth-tokens/01-get-app-token.php **

    /**
     * Create the request object.
     */
    $request = new Types\GetUserTokenRestRequest();
    $request->code = $token;
    // $request->code = 'v^1.1#i^1#I^3#r^1#p^3#f^0#t^Ul41XzA6MkIzRjJFRjA1MENDMzZCQjlGMjVERkYyMkMxMTRBM0VfMV8xI0VeMjYw';

    /**
     * Send the request.
     */
    $response = $service->getUserToken($request);

    echo '<pre>';
    print_r($response);
    echo '<pre>';
    exit;

    /**
     * Output the result of calling the service operation.
     */
    printf("\nStatus Code: %s\n\n", $response->getStatusCode());
    if ($response->getStatusCode() !== 200) {
        printf(
            "%s: %s\n\n",
            $response->error,
            $response->error_description
        );
    } else {
        printf(
            "%s\n%s\n%s\n%s\n\n",
            $response->access_token,
            $response->token_type,
            $response->expires_in,
            $response->refresh_token
        );
    }

如果有简单的代码无需使用任何 SDK 即可通过 OAuth 连接到 eBay,这就是我正在寻找的。​​p>

【问题讨论】:

    标签: oauth ebay-api


    【解决方案1】:

    我目前也在使用这个 SDK。

    我的理解是你应该放置网址:

     http://localhost/ebay-sdk-examples/oauth-tokens/02-get-user-token.php
    

    作为您在 developer.ebay.com 中您的身份验证接受的 URL1,在通过您的应用程序从 eBay 获取令牌下。

    在您设置 $token 的位置应将其设置为 $_GET['code'],因为在测试登录并接受时,您应该被重定向到上述 URL,并将 ?code=xxxx 解析回它。

    您当前设置为 $token 的值应设置为您的凭据中 authToken 的值。

    希望对您有所帮助。

    【讨论】:

    • 但 ebay 不接受 http 。它只需要 https 对吗?我们也可以在我正在使用的 sdk 中动态传递重定向 url(david sadler sdk)吗?
    【解决方案2】:

    使用我们的自定义 PHP/.NET 脚本可以生成 eBay 令牌。 eBay API 文档有很多参考

    https://viewdotnet.wordpress.com/2011/12/20/ebay-token-generation/

    以上链接包含生成 eBay Auth 所需的所有详细信息。令牌

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 2017-10-18
      • 2019-03-13
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 2017-06-23
      • 1970-01-01
      相关资源
      最近更新 更多