【问题标题】:Knowing Instagram username can I follow a user using only the API?知道 Instagram 用户名我可以只使用 API 关注用户吗?
【发布时间】:2019-09-02 21:21:34
【问题描述】:

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

我看到有取消关注的代码,但我找不到关注的代码:

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

【问题讨论】:

  • 谢谢。我编辑了我的问题

标签: php instagram


【解决方案1】:

我刚刚发现它是如何完成的。如果您知道用户名,则必须先找到带有此代码的 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());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 2017-07-22
    相关资源
    最近更新 更多