Skip to content

Modify Relationship

cosenary edited this page Sep 23, 2012 · 1 revision
  1. Login the user which should perform the action (follow / unfollow / block / unblock / approve / deny)
<?php
  $login = $instagram->getLoginUrl(array(
    'basic',
    'relationships'
  ));
  
  echo "<a href='{$login}'>Login with Instagram</a>";
?>

Thus, you are modifying a relationship, you have to add the according scope "relationships". Get login URL.

  1. After Instagram redirects the user back to your application (API callback URL), you have to grab its access token.
<?php
  $code = $_GET['code'];
  $token = $instagram->getOAuthToken($code, true);
?>

Store the access token in your database for later usage. Further information: Authenticate user

  1. Login a user by setting its access token and follow the user with the id 1574083.
<?php
  // Set access token, previously stored in your database
  $instagram->setAccessToken($token);

  // and execute the action (in this case: follow)
  $result = $instagram->modifyRelationship('follow', 1574083);
?>
  1. A successful response should look like this:
{
  "meta": {
    "code": 200
  },
  "data": {
    "outgoing_status": "follows",
    "target_user_is_private": false
  }
}

So, you can easily check whether your request was successful, if the response-code is 200. $success = $result->meta->code;

Clone this wiki locally