【问题标题】:PHP Instagram friendships/create/ ErrorPHP Instagram 友谊/创建/错误
【发布时间】:2015-06-19 17:48:13
【问题描述】:

我尝试在 Instagram 中建立友谊/创建/功能,但出现了一些错误。

帐户/登录功能正在运行。

friendships/create 错误:“请更新您的 Instagram 应用以继续关注。”

require_once("instagram.php");
$username = '';
$password = '';
$agent = 'Instagram 6.21.2 Android (19/4.4.2; 480dpi; 1152x1920; Meizu; MX4; mx4; mt6595; en_US)';
$guid = GenerateGuid();
$device_id = "android-".$guid;
$data ='{"device_id":"'.$device_id.'","guid":"'.$guid.'","username":"'.$username.'","password":"'.$password.'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
$sig    =   GenerateSignature($data);
$data   =   'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
$login  =   SendRequest('accounts/login/', true, $data, $agent, false);
print_r($login);

/**********

Login working successfully! No problem...

***********/

/*********
But error area is here.
**********/

$device_id = "android-".$guid;
$data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","device_timestamp":"'.time().'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
$sig            =   GenerateSignature($data);
$new_data       =   'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=6';
$follow         =   SendRequest('friendships/create/29180689', true, $new_data, $agent, true);

=== instagram.php ===

function SendRequest($url, $post, $post_data, $user_agent, $cookies) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://instagram.com/api/v1/'.$url);
/*
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
*/
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

if($post) {
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}

if($cookies) {
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');            
} else {
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
}

$response = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($http, $response);
}
function GenerateGuid() {
 return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', 
        mt_rand(0, 65535), 
        mt_rand(0, 65535), 
        mt_rand(0, 65535), 
        mt_rand(16384, 20479), 
        mt_rand(32768, 49151), 
        mt_rand(0, 65535), 
        mt_rand(0, 65535), 
        mt_rand(0, 65535));
}
function GenerateSignature($data) {
 return hash_hmac('sha256', $data, '25eace5393646842f0d0c3fb2ac7d3cfa15c052436ee86b5406a8433f54d24a5');
}

【问题讨论】:

  • 您找到解决方法了吗?

标签: php instagram instagram-api


【解决方案1】:

改变这一行

$data ='{"device_id":"'.$device_id.'","guid":"'.$guid.'","username":"'.$username.'","password":"'.$password.'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';

$data = '{"user_id":"'.$userId.'","_uuid":"'.$guid.'","_uid":"'.$loggedInUserId.'"}';

并改变这一行

SendRequest('friendships/create/29180689', true, $new_data, $agent, true);

SendRequest('friendships/create/29180689/', true, $new_data, $agent, true);

【讨论】:

    【解决方案2】:

    修改这一行:

    $data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","device_timestamp":"'.time().'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
    

    成为

    $data = '{"user_id":"'.$user_id.'","device_id":"'.$device_id.'","guid":"'.$guid.'","device_timestamp":"'.time().'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
    

    您错过了请求中的user_id 参数。

    【讨论】:

    • $user_id$username一样吗?
    【解决方案3】:

    您正在尝试使用私有 API,这是 Instagram 使用条款所不允许的,因此只有在那里工作的人才知道这里缺少什么。

    这里有一些公共 API 可以实现您想做的事情:https://instagram.com/developer/endpoints/relationships/#post_relationship

    【讨论】:

    • 我的应用是新的。所以我不能添加关系范围。您知道新应用的解决方案吗?
    • 您必须提交应用程序进行审核,然后您才能使用关系范围。没有其他方法可以绕过 afaik。
    猜你喜欢
    • 2017-02-27
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2015-07-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多