Skip to content

Instantly share code, notes, and snippets.

@cosenary
Last active December 25, 2020 07:13
Show Gist options
  • Save cosenary/8322459 to your computer and use it in GitHub Desktop.
Save cosenary/8322459 to your computer and use it in GitHub Desktop.
Instagram API class - follow user example
<?php
require 'Instagram.php';
use MetzWeb\Instagram\Instagram;
$instagram = new Instagram(array(
'apiKey' => 'YOUR_APP_KEY',
'apiSecret' => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK' // must point to success.php
));
// set user's accesstoken (can be received after authentication)
$instagram->setAccessToken("2823787.9687902.21u77429n3r79o08233122306fa78902");
// follow user (snoopdogg)
$result = $instagram->modifyRelationship('follow', 1574083);
// receive the list of users this user follows
$follows = $instagram->getUserFollows();
// dump response object
echo '<pre>';
print_r($follows);
echo '<pre>';
@natureluvs
Copy link

when i run this,

$result = $instagram->modifyRelationship('follow', {valid user id});

// dump response object

print_r($result);

i'm getting the following error message, though my instagram profile doesn't have a link. Please help me understand what could be wrong

stdClass Object
(
[meta] => stdClass Object
(
[error_type] => APIError
[code] => 400
[error_message] => It looks like your profile contains a link (96.171.140.76) that is not allowed.
)

)

@canerd7u
Copy link

canerd7u commented Jul 3, 2015

I get an error in the code. What is the reason ?

object(stdClass)#2 (1) { ["meta"]=> object(stdClass)#3 (3) { ["error_type"]=> string(25) "OAuthPermissionsException" ["code"]=> int(400) ["error_message"]=> string(201) "This request requires scope=relationships, but this access token is not authorized with this scope. The user must re-authorize your application with scope=relationships to be granted write permissions." } }

@random-robbie
Copy link

i think reading through you have to be a company to be able to do any post requests or delete.

It's hidden out the way i've nearly built my app and found this to be an issue

@devkhn
Copy link

devkhn commented Aug 9, 2015

Can anybody please tell me how do I get the ID?
like the ID you used here 1574083
I have never used Instagram and now I have to make an instagram app for a client. I don't know what's with the user profile IDs and how to get them. Since most users only have this username eg
username:ammarhasme

@rifkiferdian
Copy link

Even though you are adding scope as likes+relationships, instagram will give you basic permissions only. Instagram does not give you the permission to update relationship, post like and comments until you submit the app for review. With basic permissions you can view the people who liked your posts but you can not make like or comment to a post and can not update relationship status like follow/unfollow/block/unblock/ignore. For more details on submitting you app refer this
https://help.instagram.com/contact/185819881608116

@tiagokotryk
Copy link

does this follow somebody's followers?

@sansurcoder
Copy link

ı have a instagram follow.php like.php but the user free 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment