Example #1
0
/**
 * https://dev.twitter.com/rest/reference/post/friendships/destroy
 * @param $param
 * Unfollow a user
 */
function friendshipDestroy($param)
{
    $url = $param['api_end_point'] . '/friendships/destroy.json';
    $user_id = $param['params']['user_id'];
    $requestMethod = 'POST';
    $postFields = array("user_id" => $user_id);
    $twitter = new TwitterAPIExchange($param['settings']);
    $response = $twitter->buildOauth($url, $requestMethod)->setPostfields($postFields)->performRequest();
    //save to db
    if (!array_key_exists("errors", json_decode($response))) {
        $current_user = json_decode($_SESSION['current_user'], true);
        $source_id = $current_user['id'];
        $target_id = $user_id;
        $model = new Model();
        $model->deleteFollower($source_id, $target_id);
    }
    return $response;
}