Obtain location id from latitude and longitude on Instagram API and obtain the image

Asked 2 years ago, Updated 2 years ago, 135 views

<?php
    $client_id = 'my_client_id';
    $client_secret='my_client_secret';
    $redirect_uri='my_redirect_uri';

    // Obtain access tokens and convert JSON to object format
    $obj=json_decode(@file_get_contents(
        "https://api.instagram.com/oauth/access_token",
        false,
        stream_context_create(
            array("http" =>array(
                "method" = > "POST",
                "content" = > http_build_query(array(
                    "client_id" = > $client_id,
                    "client_secret" = > $client_secret,
                    "grant_type" = > "authorization_code",
                    "redirect_uri" = > $redirect_uri,
                    "code" = > $_GET["code"],
                )),
            ))
        )
    ));

    $user_id = $obj->user->id;
    $user_name = $obj->user->username;
    $user_picture=$obj->user->profile_picture;
    $access_token=$obj->access_token;

    header("Content-Type:text/html; charset=UTF-8";

    $params=array(
        "access_token" = > $access_token,
        "lat" = > "35.69691",
        "lng" = > "139.793512",
    );

    $query=http_build_query($params);

    $request_url="https://api.instagram.com/v1/locations/search";
 
    $obj=json_decode(@file_get_contents("{$request_url}?{$query}"));
 
    foreach($obj->data as$item){
    // ID, name, latitude, longitude
        $id = $item->id;
        $name = $item->name;
        $latitude=$item->latitude;
        $longitude=$item->longitude;

        echo "{$name} (location ID: {$id}/lat: {$latitude} long: {$longitude}";
    }
?>

I would like to do this while looking at the website, but what should I do after this if I want to get a list of images with a specific id (here, Ryogoku Kokugikan)?
I added the following code by myself, but it didn't work, so I'm worried.

$request_url2="https://api.instagram.com/v1/locations/"

$obj=json_decode(@file_get_contents("{$request_url2}/{$id}/media/recent?access_token={$access_token}"));

// Individual media information
foreach($obj->data as$item){
    $text = $item->caption->text;
    $image_file=$item->images->standard_resolution->url;

    // output
    echo"{$text}:<img src=\"$image_file\">";
}

instagram webapi

2022-09-30 20:48

1 Answers

https://embedsocial.jp/blog/instagram-api-changes-2020-2/

According to the above page, the old Instagram API was discontinued on June 29, 2020.

It also says, "To protect your privacy, your image will no longer contain location information."

If the image no longer has location information (latitude and longitude), it may affect applications such as the question.


2022-09-30 20:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.