[英]Problems with making ebay REST api call
我編寫了以下代碼:
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“:”權限不足,無法滿足請求。“}]}”
我不知道出了什么問題,我認為如果我獲得了令牌,它應該授予我使用我的帳戶進行操作的權限。 有人可以幫我嗎?
看起來您已經創建了一個Application令牌 。 為了在涉及賣家賬戶的eBay上執行API操作,您必須創建一個用戶令牌。 文檔中對此進行了說明 。 請注意,獲取用戶令牌所涉及的過程要求用戶登錄其eBay帳戶以向您的應用程序授予權限。 該過程與獲取應用程序令牌非常不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.