我尝试在不使用instagram api的情况下更改我的Instagram帐户中的个人资料图片。我抓住了Chrome的请求。
curl 'https://www.instagram.com/accounts/web_change_profile_picture/' -H 'origin: https://www.instagram.com' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4' -H 'x-requested-with: XMLHttpRequest' -H 'cookie: mid=WUMaVwALAAGRN0wj-Bw6twtz5Avs; sessionid=IGSC29354409c83fe0b63cc73e01822b9153388025ec66c5ad2d9a8776facedf5127%3Ab96MBCQhTyVQcf6CrqhAb53sb2egQ2wv%3A%7B%22_auth_user_id%22%3A5598585811%2C%22_auth_user_backend%22%3A%22accounts.backends.CaseInsensitiveModelBackend%22%2C%22_auth_user_hash%22%3A%22%22%2C%22_token_ver%22%3A2%2C%22_token%22%3A%225598585811%3A3JEQqPM55rIq5oZlWJViaj2m9ZcF6gVQ%3A42baad7c084a791643c80489099212c87d0734f6d65bfd077af438ebee89ba2e%22%2C%22_platform%22%3A4%2C%22last_refreshed%22%3A1497569889.5952250957%2C%22asns%22%3A%7B%22time%22%3A1497569890%2C%2289.65.108.213%22%3A6830%7D%7D; ig_mcf_shown=1655250190870; ig_vw=1920; ig_pr=1; rur=FRC; csrftoken=0rXzq6VH9YQ2LLHD4uJaq0jSOOIt5B9z; ds_user_id=5598585811' -H 'x-csrftoken: 0rXzq6VH9YQ2LLHD4uJaq0jSOOIt5B9z' -H 'pragma: no-cache' -H 'x-instagram-ajax: 1' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundarycqpuFD4uRAhkxVFt' -H 'accept: */*' -H 'cache-control: no-cache' -H 'authority: www.instagram.com' -H 'referer: https://www.instagram.com/kurwamac3/' --data-binary $'------WebKitFormBoundarycqpuFD4uRAhkxVFt\r\nContent-Disposition: form-data; name="profile_pic"; filename="profilepic.jpg"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundarycqpuFD4uRAhkxVFt--\r\n' --compressed
我试着编写php脚本,但这段代码不起作用。没有任何事情发生。
... login to instagram account ...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/accounts/web_change_profile_picture/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@profilepic.jpg;filename=profilepic.jpg'));
$headers = [
'origin: https://www.instagram.com',
'accept-language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4',
'x-requested-with: XMLHttpRequest',
'x-csrftoken: '.$csrf[1][0],
'x-instagram-ajax: 1',
'accept: */*',
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'content-type: image/jpeg',
'authority: www.instagram.com',
'referer: https://www.instagram.com/'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/'.$login.'.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/'.$login.'.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo $server_output;
响应:
{"changed_profile": true, "id": 5598585811, "has_profile_pic": false, "profile_pic_url": "https://scontent.cdninstagram.com/t51.2885-19/11906329_960233084022564_1448528159_a.jpg", "profile_pic_url_hd": "https://scontent.cdninstagram.com/t51.2885-19/11906329_960233084022564_1448528159_a.jpg", "status": "ok"}
我有" profilepic.jpg"在同一目录中。
Greetigs。
答案 0 :(得分:0)
迟到总比不到好。
更改为此
CURLOPT_POSTFIELDS => array(
'profile_pic' => new CURLFILE('full imagepath'),
'filename' => 'profilepic.jpg'
),