进行ebay REST api调用的问题

时间:2017-03-29 11:58:50

标签: rest ebay-api

我写了以下代码:

    include('httpful.phar');
include('config.php');
use \Httpful\Request;

class fullfil_pol_data{
    public $name='1dzien';
    public $marketplace='EBAY_PL';
    public $category=array('name' => 'ALL_EXCLUDING_MOTORS_VEHICLES');
    public $czas_wysylki=array('value'=> 1, 'unit'=>'DAY');
}
class aukcja{
    public $ilosc;
    public $cat_id;
    public $format;
    public $opis;
}
class token{
    public $token;
    private $duration;
    private $starts;
    public function __construct($t, $d){
        $this->token=$t;
        $this->duration=$d;
        $this->starts=time();
    }
    public function check(){
        if($this->duration+$this->starts >= time()-15*60) ibej::get_token();
    }
}
class ibej{
    private $token;
    private $sandbox=true;
    public function get_token()
    {
        if(this->sandbox) $url='https://api.sandbox.ebay.com/identity/v1/oauth2/token';
        $req= Request::post($url)->addHeader('Content-Type', 'application/x-www-form-urlencoded')
                                        ->addHeader('Authorization', 'Basic '.PASSES)
                                        ->body("grant_type=client_credentials&redirect_uri=Marketing_Desig-Marketin-wystaw-blzyg&scope=https://api.ebay.com/oauth/api_scope")->send();
        $this->token = new token($req->body->access_token, $req->body->expires_in);
        var_dump($this->token);
    }

    /*$url='https://api.sandbox.ebay.com/sell/inventory/v1/offer';
    //$req= Request::post($url)->addHeader('Authorization', 'Bearer '.$token)
        //                          ->addHeader('X-EBAY-C-MARKETPLACE-ID', 'EBAY-PL')
        */
    public function post_fullfilment_policy()
    {
        if(this->sandbox) $url='https://api.sandbox.ebay.com/sell/account/v1/fulfillment_policy';
        $test= new fullfil_pol_data;
        $req= Request::post($url)->addHeader('Authorization', 'Bearer '.$this->token->token)
                                ->addHeader('Accept', 'application/json')
                                ->addheader('Content-Type', 'application/json')
                                ->addHeader('X-EBAY-C-MARKETPLACE-ID', 'EBAY-US')
                                ->body(json_encode($test))->send();
        var_dump($req);
    }
}
$ibej_api = new ibej;
$ibej_api->get_token();
$ibej_api->post_fullfilment_policy();

当我尝试使用 - > post_fullfilment_policy()方法调用fullfilmentpolicy(http://developer.ebay.com/Devzone/rest/api-ref/account/fulfillment_policy__post.html)时,我发现此错误:

“{”errors“:[{”errorId“:1100,”domain“:”ACCESS“,”category“:”REQUEST“,”message“:”拒绝访问“,”longMessage“:”权限不足以完成请求。“}]}”

我不知道出了什么问题,我估计如果我已经获得了令牌,它应该授予我使用我的帐户执行操作的权限。有谁可以帮助我?

1 个答案:

答案 0 :(得分:1)

您好像已经创建了Application token。要在易趣上执行涉及卖家帐户的API操作,您必须创建用户令牌。documentation对此进行了解释。请注意,获取用户令牌所涉及的过程要求用户登录其eBay帐户以授予您的应用程序权限。该过程与获取应用程序令牌非常不同。