Open hussainsheikh048 opened 3 years ago
What methods are you referring to? You're able to add and remove followers.
Have a look at https://github.com/NicklasWallgren/instagram-api/blob/master/src/Traits/MakeFriendshipsRequestsAccessible.php
No, I'm not referring to add and remove followers, Instagram has a new feature to add a friend into a close friend list.
I've tried to add a function inside your library to see if it's working or not, but my bad it's not working...
MakeFriendshipsRequestsAccessible.php
public function setBestFriend(): FollowingResponse
{
return PromiseUtils::wait($this->getClient()->setBestFriend());
}
FriendshipsFeaturesTrait.php
public function setBestFriend(): PromiseInterface
{
return $this->authenticated(function (): PromiseInterface {
$request = $this->buildRequest('friendships/set_besties', new FollowResponse())
->addCSRFTokenAndUserId($this->session)
->addUuid($this->session)
->addPayloadParam('user_id', '2108351612')
->addPayloadParam('add', '2108351612')
// ->addQueryParam('add', ['2108351612'])
->setPayloadSerializerType(PayloadSerializerFactory::TYPE_SIGNED);
return $this->call($request);
});
}
I've found the API code from the NODE API.
async setBesties(input = {}) {
const { body } = await this.client.request.send({
url: `/api/v1/friendships/set_besties/`,
method: 'POST',
form: this.client.request.sign({
_csrftoken: this.client.state.cookieCsrfToken,
_uid: this.client.state.cookieUserId,
device_id: this.client.state.deviceId,
_uuid: this.client.state.uuid,
module: 'favorites_home_list',
source: 'audience_manager',
add: input.add,
remove: input.remove,
}),
});
return body.friendship_statuses;
}
Alright, the following example seems to work. You are welcome to create a PR.
The response looks like this.
{
"friendship_statuses":{
"2108351612":{
"following":true,
"is_private":false,
"incoming_request":false,
"outgoing_request":false,
"is_blocking_reel":false,
"is_muting_reel":false,
"is_bestie":true,
"is_restricted":false
}
},
"status":"ok"
}
MakeFriendshipsRequestsAccessible
/**
* @param array $userIds
* @return FollowingResponse
*/
public function addBestFriend(array $userIds): FollowResponse
{
return PromiseUtils::wait($this->getClient()->addBestFriend($userIds));
}
FriendshipsFeaturesTrait
/**
* @param array $userIds
* @return PromiseInterface
*/
public function addBestFriend(array $userIds): PromiseInterface
{
return $this->authenticated(function () use ($userIds): PromiseInterface {
$request = $this->buildRequest('friendships/set_besties/', new FollowResponse())
->addPayloadParam('module', 'favorites_home_list')
->addPayloadParam('source', 'audience_manager')
->addCSRFTokenAndUserId($this->session)
->addUuid($this->session)
->addPayloadParam('add', $userIds)
->addPayloadParam('remove', [])
->setPayloadSerializerType(PayloadSerializerFactory::TYPE_SIGNED);
return $this->call($request);
});
}
/**
* @param array $userIds
* @return PromiseInterface
*/
public function removeBestFriend(array $userIds): PromiseInterface
{
return $this->authenticated(function () use ($userIds): PromiseInterface {
$request = $this->buildRequest('friendships/set_besties/', new FollowResponse())
->addPayloadParam('module', 'favorites_home_list')
->addPayloadParam('source', 'audience_manager')
->addPayloadParam('block_on_empty_thread_creation', 'false')
->addCSRFTokenAndUserId($this->session)
->addUuid($this->session)
->addPayloadParam('add', [])
->addPayloadParam('remove', $userIds)
->setPayloadSerializerType(PayloadSerializerFactory::TYPE_SIGNED);
return $this->call($request);
});
}
Hi Nicklaws,
Thanks for your response.
I'm still getting errors.
Uncaught Instagram\SDK\Exceptions\ApiResponseException in E:\xampp\htdocs\instagram-api-master\src\Response\Serializers\AbstractResponseSerializer.php:137
Hi Nick,
Imran's here, with my another account.
@hussainsheikh048 Does the ApiResponseException
contain any descriptive error message?
Fatal error: Uncaught Instagram\SDK\Exceptions\ApiResponseException in E:\xampp\htdocs\instagram-api-master\src\Response\Serializers\AbstractResponseSerializer.php:137
Stack trace:
#0 E:\xampp\htdocs\instagram-api-master\src\Response\Serializers\AbstractResponseSerializer.php(59): Instagram\SDK\Response\Serializers\AbstractResponseSerializer::toException(NULL, Object(Instagram\SDK\Response\Responses\Friendships\FollowResponse))
#1 E:\xampp\htdocs\instagram-api-master\src\Client\Client.php(174): Instagram\SDK\Response\Serializers\AbstractResponseSerializer->decode(Object(GuzzleHttp\Psr7\Response), Object(Instagram\SDK\Client\Client))
#2 E:\xampp\htdocs\instagram-api-master\src\Utils\PromiseUtils.php(34): Instagram\SDK\Client\Client->Instagram\SDK\Client\{closure}()
#3 E:\xampp\htdocs\instagram-api-master\vendor\guzzlehttp\promises\src\TaskQueue.php(48): Instagram\SDK\Utils\PromiseUtils::Instagram\SDK\Utils\{closure}()
#4 E:\xampp\htdocs\instagram-api-master\vendor\guzzlehttp\guzzle\src\Handler\CurlMultiHandler.php(118): Gu in E:\xampp\htdocs\instagram-api-master\src\Response\Serializers\AbstractResponseSerializer.php on line 137
here is the full error, the message details are below. (I think the error is for the serializer, like we're passing an array to request something)
$responseInstance->getErrorType() is null;
$responseInstance->getMessage() is empty;
Thanks. It's a bit strange, it works fine on my end, with the code posted above.
$instagram->addBestFriend(['2108351612']);
Could you dump the whole response body?
What php version you’re using?
Sent from my iPhone
On 19-Jul-2021, at 12:01 AM, NicklasWallgren @.***> wrote:
Thanks. It's a bit strange, it works fine on my end, with the code posted above.
$instagram->addBestFriend(['2108351612']); — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
What php version you’re using? … Sent from my iPhone On 19-Jul-2021, at 12:01 AM, NicklasWallgren @.***> wrote: Thanks. It's a bit strange, it works fine on my end, with the code posted above. $instagram->addBestFriend(['2108351612']); — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Hey, I'm running 7.2, but I don't think it's related to the issue. You are retrieving an API error, and the answer probably lies in the API response.
yea, it's working fine, i'll make PR soon. many thanks
Hi Nick, You've any idea how to bypass two-factor authentication?
Hey, you won't be able to bypass 2fa, but it's fully possible to add 2fa support by implementing the accounts/two_factor_login/
api endpoint.
I don't have time to implement support for 2fa at the moment, so a PR is welcome.
But it didn’t fill auto code
Sent from my iPhone
On 20-Jul-2021, at 8:11 PM, NicklasWallgren @.***> wrote:
Hey, you won't be able to bypass 2fa, but it's fully possible to add 2fa support by implementing the accounts/two_factor_login/ api endpoint.
I don't have time to implement support for 2fa at the moment, so a PR is welcome.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Hi Nick,
I was trying to make a request for 2fa, i figure it out we need to send identifier with the mobile code, but i can't see any identifier in the error response, i've attached the screenshot.
Here is instagram request where i dentifier the parameters.
Login request 404 response if 2fa enable:
After given 2fa code request:
Hey,
You can get hold of the 2fa identifier from the response of the accounts/login/
api endpoint.
The response includes two_factor_required
as well as two_factor_info
which contains the two_factor_identifier
Hi,
I want to hold 2fa identifier but i can't see identifier in the error response. here is response.
here is code for print the response:
try {
}
} catch (\Instagram\SDK\Exceptions\ApiResponseException $e) {
echo "ApiResponseException";
var_dump($e->getResponse());
}
Hey,
The identifier is present in the raw json response, but is not specified in the SessionResponse
class. You'll need to extend the class with new fields.
You can get hold of the raw response body at https://github.com/NicklasWallgren/instagram-api/blob/master/src/Response/Serializers/AbstractResponseSerializer.php#L56
Have you managed to get it working?
I've not worked yet, but hopefully work tomorrow and make it work.
I can confirm that @NicklasWallgren addition above is working...implemented and tested.
Hi Nick,
Still have an issue with the 2fa login,
MakeAccountRequestAccessible.php
public function twoFactorLogin(string $username, string $identifier, string $verificationCode): AuthenticatedUserResponse
{
return PromiseUtils::wait($this->twoFactorLoginPromise($username, $identifier, $verificationCode));
}
public function twoFactorLoginPromise(string $username, string $identifier, string $verificationCode): PromiseInterface
{
return $this->getClient()->twoFactorLogin($username, $identifier, $verificationCode);
}
Here is the actual function
AccountFeaturesTrait.php
public function twoFactorLogin(string $username, string $identifier, string $verificationCode): PromiseInterface
{
return $this->headers()->then(function () use ($username, $identifier, $verificationCode): PromiseInterface {
$request = $this->buildRequest('accounts/two_factor_login/', new SessionResponse());
$payload = [
'identifier' => $identifier,
'trust_signal' => false,
'username' => $username,
'verificationCode' => $verificationCode,
'verification_method' => 1,
'queryParams' => json_encode(['next' => '/']),
];
print_r($payload);
$request->setPayload($payload, PayloadSerializerFactory::TYPE_SIGNED)
->setResponseSerializer(new LoginResponseSerializer($this->device, $this->client));
return $this->call($request);
});
}
That's still saying invalid parameter, is there something wrong?
https://i.instagram.com/api/v1/si/fetch_headers/
Array
(
[identifier] => kqpGR0xtV2p1djEy2gF8Rm9UbXU1ZjNyTEUvRnBhL3ovVGpYaFVTR0lFQ1dFNmJsSTB0VXlaU1JwWUlxNEpScWI0SXZXdC9FWDdTTlNIOXRhQ1FEK3RnUENwcStsMUhXRXBQQUpWam5aSXgraGVSbk93WTRrTXZXZ1kvU0UzSEhwRVMrMmp2dU8ydTF5RGoxdjRISjV0a002ZldoOEZwMDRaY1Y5ZXRYOFJTL014dm1DS1R5QWlockhvQjc2dkRRcjc0T09ZZGszVzN0UCt6clY4cjRwRUU0NkJzbXRWd2ZBRDNidmlGRlBsWXFRY3NkSXZZRWl3TnQ5M3gzNkNYS1llVnJBaW95aW5GaXNMbHZJYkoxcjRYWXhhUHlBaXl3Z3FqVFVrTXllRUdNZng1L2hka0xsN3VobzFrYzVMdWR1c2Fxb005b041NXVGUXpkN3pXRlM1aHREY2ZtU3NrelhJL2lhNG5Da3pHeU1xZEF0a1lncVVMTXRnVDh5TklCOHdjR0FKd2R3QUE=
[trust_signal] =>
[username] => hussainsheikh4161
[verificationCode] => 848241
[verification_method] => 1
[queryParams] => {"next":"\/"}
)
https://i.instagram.com/api/v1/accounts/two_factor_login/
0144Invalid ParametersInstagram\SDK\Response\Responses\User\SessionResponse Object
(
[loggedInUser:Instagram\SDK\Response\Responses\User\SessionResponse:private] =>
[session:Instagram\SDK\Response\Responses\User\SessionResponse:private] =>
[status:protected] => fail
[errorType:protected] => invalid_parameters
[message:protected] => Invalid Parameters
[invalidCredentials:protected] =>
)
Hey, I'll look into adding support for 2fa tomorrow.
I can confirm that @NicklasWallgren addition above is working...implemented and tested.
@NicklasWallgren I can create PR, please give me permissions
@xsinisa Thanks, feel free to open a PR. https://github.com/NicklasWallgren/instagram-api/pulls
@xsinisa is it 2fa working for you?
Hi,
Can we add/remove followers to close friends I've checked dilame repository supported.
https://github.com/dilame/instagram-private-api