繁体   English   中英

知道Instagram用户名后,我可以仅使用API​​跟踪用户吗?

[英]Knowing Instagram username can I follow a user using only the API?

这个问题被问了很多,但是最后更新的答案是3-4年前。 我想知道我是否能够使用由mgp25( https://github.com/mgp25/Instagram-API )制造的Instagram的PHP API,并在我的商业Instagram帐户上关注一个用户,知道他的Instagram用户名,例如该用户名-女孩乐队

我看到有不遵循的代码,但是找不到以下代码:

/**
 * Remove one of your followers.
 *
 * @param string $userId Numerical UserPK ID.
 *
 * @throws \InstagramAPI\Exception\InstagramException
 *
 * @return \InstagramAPI\Response\FriendshipResponse
 */
public function removeFollower(
    $userId)
{
    return $this->ig->request("friendships/remove_follower/{$userId}/")
        ->addPost('_uuid', $this->ig->uuid)
        ->addPost('_uid', $this->ig->account_id)
        ->addPost('_csrftoken', $this->ig->client->getToken())
        ->addPost('user_id', $userId)
        ->addPost('radio_type', 'wifi-none')
        ->getResponse(new Response\FriendshipResponse());
}

我只是发现如何做到。 如果您知道用户名,则必须先找到具有以下代码的Instagram ID(数字):

$id = $ig->people->getUserIdForName('girlinred.band');

然后,当您拥有ID时,您可以简单地运行以下代码来关注成员

$ig->people->follow($id);

如果需要,这里是从API本身获取的完整方法:

/**
 * Follow a user.
 *
 * @param string $userId Numerical UserPK ID.
 *
 * @throws \InstagramAPI\Exception\InstagramException
 *
 * @return \InstagramAPI\Response\FriendshipResponse
 */
public function follow(
    $userId)
{
    return $this->ig->request("friendships/create/{$userId}/")
        ->addPost('_uuid', $this->ig->uuid)
        ->addPost('_uid', $this->ig->account_id)
        ->addPost('_csrftoken', $this->ig->client->getToken())
        ->addPost('user_id', $userId)
        ->addPost('radio_type', 'wifi-none')
        ->getResponse(new Response\FriendshipResponse());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM