【问题标题】:OAuth 2.0 not working with the new Envato APIOAuth 2.0 不适用于新的 Envato API
【发布时间】:2015-07-09 04:54:26
【问题描述】:

嘿,我只是 CURL 的学习者,我正在通过这个新的 Envato 学习 API。我不知道我在犯什么错误,我可以得到代码但不能使用https://build.envato.com/api#oauth中的POST方法调用

$ch = curl_init();

$url = 'https://api.envato.com/tokengrant_type=authorization_code&code='$_GET["code"]'&client_id=1&client_secret=MYSECRETKEY?type=post';

//makes the array suitable for sending
$items = http_build_query($member);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($members));
curl_setopt($ch, CURLOPT_POSTFIELDS, $items);

//execute
$result = curl_exec($ch);

//close curl session / free resources
curl_close($ch);


//ends

`

【问题讨论】:

    标签: php json curl oauth-2.0


    【解决方案1】:

    您正在使用未定义的变量 $member 即未定义的值来填写 POST 正文。此外,在 URL 中包含查询参数的参数实际上应该是 POST 正文的一部分。这应该有效:

    $ch = curl_init('https://api.envato.com/token');
    
    $member = array(
      'grant_type' => 'authorization_code',
      'code' => $_GET["code"],
      'client_id' => "1",
      'client_secret' => 'MYSECRETKEY'
    );
    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, True);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($member));
    
    $result = curl_exec($ch);    
    curl_close($ch);
    

    【讨论】:

    • 如果它有效,那么请接受并可能支持答案
    猜你喜欢
    • 2018-04-28
    • 2015-11-22
    • 2015-10-18
    • 2012-10-15
    • 2017-11-22
    • 1970-01-01
    • 2012-02-01
    • 2015-04-24
    • 2014-03-26
    相关资源
    最近更新 更多