Bonjour,
Comment poster des photos sur instagram à partir d'une application web en Php ou alors en JS ?
Merci,
Christophe,
Bonjour,
Comment poster des photos sur instagram à partir d'une application web en Php ou alors en JS ?
Merci,
Christophe,
salut,moi aussi je cherche comment le faire quelqu'un n'aurais pas une solution
Salut,
oui c'est possible
tu peux utiliser ce code en php:
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 function SendRequest($url, $post, $post_data, $user_agent, $cookies) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://i.instagram.com/api/v1/'.$url); 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 GenerateUserAgent() { $resolutions = array('720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320'); $versions = array('GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100'); $dpis = array('120', '160', '320', '240'); $ver = $versions[array_rand($versions)]; $dpi = $dpis[array_rand($dpis)]; $res = $resolutions[array_rand($resolutions)]; return 'Instagram 4.'.mt_rand(1,2).'.'.mt_rand(0,2).' Android ('.mt_rand(10,11).'/'.mt_rand(1,3).'.'.mt_rand(3,5).'.'.mt_rand(0,5).'; '.$dpi.'; '.$res.'; samsung; '.$ver.'; '.$ver.'; smdkc210; en_US)'; } function GenerateSignature($data) { return hash_hmac('sha256', $data, 'b4a23f5e39b5929e0666ac5de94c89d1618a2916'); } function GetPostData($filename) { if(!$filename) { echo "The image doesn't exist ".$filename; } else { $post_data = array('device_timestamp' => time(), 'photo' => '@'.$filename); return $post_data; } } // Set the username and password of the account that you wish to post a photo to $username = 'ig_username'; $password = 'ig_password'; // Set the path to the file that you wish to post. // This must be jpeg format and it must be a perfect square $filename = 'pictures/test.jpg'; // Set the caption for the photo $caption = "Test caption"; // Define the user agent $agent = GenerateUserAgent(); // Define the GuID $guid = GenerateGuid(); // Set the devide ID $device_id = "android-".$guid; /* LOG IN */ // You must be logged in to the account that you wish to post a photo too // Set all of the parameters in the string, and then sign it with their API key using SHA-256 $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=4'; $login = SendRequest('accounts/login/', true, $data, $agent, false); if(strpos($login[1], "Sorry, an error occurred while processing this request.")) { echo "Request failed, there's a chance that this proxy/ip is blocked"; } else { if(empty($login[1])) { echo "Empty response received from the server while trying to login"; } else { // Decode the array that is returned $obj = @json_decode($login[1], true); if(empty($obj)) { echo "Could not decode the response: ".$body; } else { // Post the picture $data = GetPostData($filename); $post = SendRequest('media/upload/', true, $data, $agent, true); if(empty($post[1])) { echo "Empty response received from the server while trying to post the image"; } else { // Decode the response $obj = @json_decode($post[1], true); if(empty($obj)) { echo "Could not decode the response"; } else { $status = $obj['status']; if($status == 'ok') { // Remove and line breaks from the caption $caption = preg_replace("/\r|\n/", "", $caption); $media_id = $obj['media_id']; $device_id = "android-".$guid; $data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","media_id":"'.$media_id.'","caption":"'.trim($caption).'","device_timestamp":"'.time().'","source_type":"5","filter_type":"0","extra":"{}","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'; $sig = GenerateSignature($data); $new_data = 'signed_body='.$sig.'.'.urlencode($data).'&ig_sig_key_version=4'; // Now, configure the photo $conf = SendRequest('media/configure/', true, $new_data, $agent, true); if(empty($conf[1])) { echo "Empty response received from the server while trying to configure the image"; } else { if(strpos($conf[1], "login_required")) { echo "You are not logged in. There's a chance that the account is banned"; } else { $obj = @json_decode($conf[1], true); $status = $obj['status']; if($status != 'fail') { echo "Success"; } else { echo 'Fail'; } } } } else { echo "Status isn't okay"; } } } } } }
pour les explications (en anglais) c'est sur ce blog: http://batuhan.org/instagram-photo-upload-with-php/
à savoir qu'aucun API officiel ne permet l'upload... donc c'est du "sans garanties, à vos risques et péril"
sinon, pour toutes les autres fonctionnalités vous avez des tutoriels en anglais sur le site d'IBM: http://www.ibm.com/developerworks/library/x-instagram1/ et http://www.ibm.com/developerworks/li...am2/index.html.
bonjour,ok merci pour votre reponse
curl permet de faire des échanges inter-serveurs comme si c'était un client web qui interrogeait le serveur cible...
si ton problème est résolu n'oublie pas de clôturer le post
ok mais je ne comprends pas bien la façon dont je doit proceder
avec ce code j'ai lu le doc que vous m'avez donné en lien mais ça ne marche pas quand j'essaie
déjà, c'est du PHP, si tu n'utilises pas ce langage,je ne pourrais pas t'aider
entre les lignes 65 et 75 tu as les variables à modifier (identifiant, mot de passe, chemin et nom de fichier, titre de l'image)
pour info, il semblerait qu'instagram passe bientôt à la double identification (internet + sms ou un truc du genre), ce qui risque de compliquer ce que vous voulez faire tous les 2... car obliger à modifier ce script voir ça pourrait le rendre inopérant...
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager