我正在使用Mailchimp的API,而且我从documentation开始坚持这一步:
Step 4: Your application must make an out-of-band request to the access_token_uri using the "code" returned
- This is a POST request
- as you can see, grant_type, client_id, client_secret, code, and redirect_uri are *all* POSTed
******************************************************************************************
access_token_uri: https://login.mailchimp.com/oauth2/token
REQUEST:
POST /oauth2/token HTTP/1.1
User-Agent: oauth2-draft-v10
Host: login.mailchimp.com
Accept: application/json
Content-Length: 198
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&client_id=635959587059&client_secret=0da3e7744949e1406b7b250051ee1a95&code=1edf2589e664fd317f6a7ff5f97b42f7&redirect_uri=http%3A%2F%2F192.168.1.8%2Foauth%2Fcomplete.php
这是我尝试过的,但$dec_respo
一直以NULL结尾:
$client_id = 'xxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxx'; //client_secret from creating app in MC (see README)
$redirect_uri = 'https%3A%2F%2Fexample.com%2Fimport%2Fsuccess_mc.html';
$code_got ='67add42184b8f71a9100f505d3f13744';
$headr = array();
$headr[] = 'Content-type: application/x-www-form-urlencoded';
$post_data = json_encode(array('grant_type'=>'authorization_code','client_id' => $client_id,'client_secret' => $client_secret, 'code'=> $code_got, 'redirect_uri'=> $redirect_uri));
$url = 'https://login.mailchimp.com/oauth2/token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
$dec_respo = (json_decode($response, true));
var_dump($dec_respo);
我在这里缺少什么?