0
votes

I'm working on a script written in php that will collect the number of posts there is with a certain hashtag. I've found the correct api here but it doesn't seem to work for me. I go through the authentication peace and receive an acnes-token but when i try to use it I get the error message:

{"meta":{"error_type":"OAuthAccessTokenException","code":400,"error_message":"The access_token provided is invalid."}}

This is the could of page instagram redirects the user to after authentication:

function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

echo $code = $_GET["code"];

$content = get_data("https://api.instagram.com/v1/tags/sweden?access_token=".$code) or die("could not open stream");
echo $content;
?>

Tankfull for any help!

1

1 Answers

3
votes

$_GET['code'] is not the access token.

You must use the code to request an access token from https://api.instagram.com/oauth/access_token.

See "Step Three: Request the access_token" in the docs.