简体   繁体   中英

Instagram php laravel access token

I was able to get the code from instagram api. The next step is to post the client_id, client_secret, grant_type, redirect_uri and code to https://api.instagram.com/oauth/access_token as shown below.

The instagram API says that "you simply have to POST this code, along with some app identification parameters, to our access_token endpoint."

 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

How can I do this in my laravel controller or php script? How do I put all these information as a variable and post it to the uri to get back the json object? Thank you

using ssh task runner

$commands = ["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"]

//       your command, the output of the command
SSH::run($commands   , function($line)
{
    echo $line.PHP_EOL;
});

OR simply using both php internal functions exec , shell_exec or system


Another approach - in case of you want to keep away of shell commands - is by using guzzle package or internal php cURL library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM