php
  • instagram
  • instagram-api
  • 2015-06-19 91 views 5 likes 
    5

    我試圖在Instagram Instagram /創建/功能,但我有一些錯誤。PHP Instagram的友誼/創建/錯誤

    帳號/登錄功能正在工作。

    友誼/創建錯誤:「請更新您的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'); 
    } 
    
    +0

    您是否找到了解決方法? –

    回答

    -1

    您正在嘗試使用私有API,它們不被Instagram的的使用條款允許的,所以只有人誰的作品有知道的在這裏失蹤。

    還有就是公共API,可以實現你想在這裏做的:https://instagram.com/developer/endpoints/relationships/#post_relationship

    +0

    我的應用程序是新的。所以我不能添加關係範圍。你知道新應用的解決方案嗎? –

    +0

    您必須提交應用以供審覈,然後才能使用關係範圍。 afaik沒有別的辦法。 –

    0

    修改這一行:

    $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參數在請求內。

    +0

    '''$ user_id''是否與''''username'''相同? –

    相關問題