_setUser 函数是私有的,您可以将私有函数编辑为公共函数,然后只有您可以使用该函数,即使您不更改它也会自动采用 _setUser 方法,因为文件夹中的会话存储处于活动状态。您可以在下面查看
protected function _login(
$username,
$password,
$forceLogin = false,
$appRefreshInterval = 1800)
{
if (empty($username) || empty($password)) {
throw new \InvalidArgumentException('You must provide a username and password to _login().');
}
// Switch the currently active user/pass if the details are different.
if ($this->username !== $username || $this->password !== $password) {
$this->_setUser($username, $password);
}
// Perform a full relogin if necessary.
if (!$this->isMaybeLoggedIn || $forceLogin) {
$this->_sendPreLoginFlow();
try {
$response = $this->request('accounts/login/')
->setNeedsAuth(false)
->addPost('phone_id', $this->phone_id)
->addPost('_csrftoken', $this->client->getToken())
->addPost('username', $this->username)
->addPost('adid', $this->advertising_id)
->addPost('guid', $this->uuid)
->addPost('device_id', $this->device_id)
->addPost('password', $this->password)
->addPost('login_attempt_count', 0)
->getResponse(new Response\LoginResponse());
} catch (\InstagramAPI\Exception\InstagramException $e) {
if ($e->hasResponse() && $e->getResponse()->isTwoFactorRequired()) {
// Login failed because two-factor login is required.
// Return server response to tell user they need 2-factor.
return $e->getResponse();
} else {
// Login failed for some other reason... Re-throw error.
throw $e;
}
}
$this->_updateLoginState($response);
$this->_sendLoginFlow(true, $appRefreshInterval);
// Full (re-)login successfully completed. Return server response.
return $response;
}
// Attempt to resume an existing session, or full re-login if necessary.
// NOTE: The "return" here gives a LoginResponse in case of re-login.
return $this->_sendLoginFlow(false, $appRefreshInterval);
}