douxiong4250 2017-06-13 05:22
浏览 393
已采纳

如何发送Curl请求[重复]

This question already has an answer here:

I have this sample code which is required for the Instagram authentication. i don't know how to do this curl in php. The step below is what i need to achieve.

Step Three: Request the access_token

Now you need to exchange the code you have received in the previous step for an access token. In order to make this exchange, you simply have to POST this code, along with some app identification parameters, to our access_token endpoint. These are the required parameters:

client_id: your client id client_secret: your client secret grant_type: authorization_code is currently the only supported value redirect_uri: the redirect_uri you used in the authorization request. Note: this has to be the same value as in the authorization request. code: the exact code you received during the authorization step. This is a sample request:

curl -F 'client_id=CLIENT_ID' \
-F 'client_secret=CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
-F 'code=CODE' \
https://api.instagram.com/oauth/access_token

If successful, this call will return a neatly packaged OAuth Token that you can use to make authenticated calls to the API. We also include the user who just authenticated for your convenience:

{ "access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d", "user": { "id": "1574083", "username": "snoopdogg", "full_name": "Snoop Dogg", "profile_picture": "..." } }

I am new to this. so i need help

</div>
  • 写回答

2条回答 默认 最新

  • douwei1174 2017-06-13 05:24
    关注

    Try this code

    $client_id = 'YOUR CLIENT ID';
        $client_secret ='YOUR CLIENT SECRET';
            $redirect_uri = 'YOUR REDIRECT URI';
        $code ='Enter your code manually';
    
        $url = "https://api.instagram.com/oauth/access_token";
        $access_token_parameters = array(
            'client_id'                =>     $client_id,
            'client_secret'            =>     $client_secret,
            'grant_type'               =>     'authorization_code',
            'redirect_uri'             =>     $redirect_uri,
            'code'                     =>     $code
        );
    
    $curl = curl_init($url);    // we init curl by passing the url
        curl_setopt($curl,CURLOPT_POST,true);   // to send a POST request
        curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters);   // indicate the data to send
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   // to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   // to stop cURL from verifying the peer's certificate.
        $result = curl_exec($curl);   // to perform the curl session
        curl_close($curl);   // to close the curl session
    
         var_dump($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)