Bonanza Api:无法让令牌工作在php中工作

时间:2015-12-23 08:15:01

标签: php api

我正在关注提供的示例=> Bonanza Api Examples

我正在尝试使用以下代码测试'addFixedPriceItem':

<?php

    $dev_name = "************";
    $cert_name = "************";

    $url = "https://api.bonanza.com/api_requests/secure_request";
    $headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
    $args = array();
    $post_fields = "fetchTokenRequest";
    echo "Request: $post_fields <BR>";
    $connection = curl_init($url);
    $curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                    CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
    curl_setopt_array($connection, $curl_options);
    $json_response = curl_exec($connection);
    if (curl_errno($connection) > 0) {
      echo curl_error($connection) . "<BR>";
      exit(2);
    }

    $response = json_decode($json_response,true);
    $token = $response['fetchTokenResponse']['authToken'];
    echo "Token: $token <BR>";

    $item['title'] = "My Item";
    $item['price'] = 30.57;
    $item['quantity'] = 1;
    $item['description'] = "This item is great.  Any html here.";
    $item['pictureDetails']['pictureURL'] = "http://www.google.com/images/logos/ps_logo2.png";
    $item['primaryCategory']['categoryId'] = 377;
    $item['shippingDetails']['shippingServiceOptions']['freeShipping'] = true;
    $args = array("item" => $item);
    $args['requesterCredentials']['bonanzleAuthToken'] = $token;

    $post_fields = "addFixedPriceItem=" .  urlencode(json_encode($args));
    echo "Request: $post_fields <BR>";

    $curl_options2 = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                    CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
    curl_setopt_array($connection, $curl_options2);
    $json_response = curl_exec($connection);
    if (curl_errno($connection) > 0) {
      echo curl_error($connection) . "<BR>";
      exit(2);
    }
    curl_close($connection);
    $response = json_decode($json_response,true);
    $itemId= $response['addFixedPriceItemResponse']['itemId'];
    echo "itemId: $itemId <BR>";


    echo "Response: <BR>";
    echo "<PRE>";
    print_r($response);
    echo "</PRE>";


    ?>

回应:

Array
(
    [ack] => Failure
    [version] => 1.0beta
    [timestamp] => 2015-12-23T00:11:53.000Z
    [errorMessage] => Array
        (
            [message] => Bonapitit::TokenNotVerified
        )

)

似乎令牌不起作用,任何人都有使用Bonanza的经验可以请求帮助吗?

1 个答案:

答案 0 :(得分:1)

您的令牌无效,因为它尚未经过验证。

fetchToken响应应该包含“authenticationURL”,它将转到Bonanza登录页面。从那里登录将验证登录的Bonanza用户的令牌。

令牌验证是Bonanza如何知道您拥有Bonanza用户的权限,可以代表他们添加商品或查看他们的私人销售信息