简体   繁体   English

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

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

This question is asked a lot, but last updated answer is from 3-4 years ago. 这个问题被问了很多,但是最后更新的答案是3-4年前。 I want to know if I am able to use the PHP API of Instagram made by mgp25 ( https://github.com/mgp25/Instagram-API ) and follow a user on my business Instagram account knowing his Instagram username for example this username - girlinred.band 我想知道我是否能够使用由mgp25( https://github.com/mgp25/Instagram-API )制造的Instagram的PHP API,并在我的商业Instagram帐户上关注一个用户,知道他的Instagram用户名,例如该用户名-女孩乐队

I saw there is unfollow code, but I can't find the follow one: 我看到有不遵循的代码,但是找不到以下代码:

/**
 * 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());
}

I just found how it could be done. 我只是发现如何做到。 If you know the username you have to find first the Instagram ID (numbers) with this code: 如果您知道用户名,则必须先找到具有以下代码的Instagram ID(数字):

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

then when you have the ID you can simple run this code to follow a member 然后,当您拥有ID时,您可以简单地运行以下代码来关注成员

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

and here is the full method taken from the API itself in case you need it: 如果需要,这里是从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