Bonjour je suis à la recherche d'un script me permetant à partir de ma page admin.php de publier un texte sur twitter
merci pour votre aide
Version imprimable
Bonjour je suis à la recherche d'un script me permetant à partir de ma page admin.php de publier un texte sur twitter
merci pour votre aide
bon voila un fichier vous permettant de poster et lire vos twitte
la fonction supp ne fonctionne pas et je ne vois pas pourquoi si vous avez un element de reponse je suis preneur
Code:
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264 <?php require_once('../Connections/xxxxx.php'); require ('../Connections/fre.php'); //// POUR SUPPRIMER UN TWITTE if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // Remplissez votre login et motdepasse $username = $username_twitter; $password = $password_twitter; // l'ID a supprimer $id_supp = $_POST['id_txitte_sup'] ; // The twitter API address $url = "http://twitter.com/statuses/destroy/".$id_supp.".xml"; //$url = "http://twitter.com/statuses/destroy/".$id_supp.".json"; echo "cette option ne fonctionne pas pour le moment // $url"; exit; // Set up et execute les procédures curl $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "$id_supp"); $buffer = curl_exec($curl_handle); // affiche les messages d'erreurs et ferme la connexion if (curl_errno($curl_handle)) { print curl_error($curl_handle); } curl_close($curl_handle); // Check la connexion et retourne un message en cas d'erreur if (preg_match("#Could not authenticate you#iU", $buffer)) die ('Erreur d\'authentification! Vérifier votre login et mdp.'); } ///// POUR PUBLIER UN TWIIT if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { // URL courte $url_twitte = $url_site.$fichier_news_twitter; if($url_courte==1) { $tinyUrl = @file('http://tinyurl.com/api-create.php?url='.urlencode($url_twitte)); // $tinyUrl[0] contiens la nouvelle url $url_message = $tinyUrl[0] ; } else { $url_message = $url_twitte; } // echo "eeee"; exit; // Remplissez votre login et motdepasse $username = $username_twitter; $password = $password_twitter; // Le message que vous voulez envoyer $message = $_POST['message'] ; $message = $message." ".$url_message; // Twitter API address $url = "http://twitter.com/statuses/update.xml"; // Set up et execute les procédures curl $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message"); $buffer = curl_exec($curl_handle); // affiche les messages d'erreurs ou ferme la connexion if (curl_errno($curl_handle)) { print curl_error($curl_handle); } curl_close($curl_handle); // Check la connexion et retourne un message en cas d'erreur if (preg_match("#Could not authenticate you#iU", $buffer)) die ('Erreur d\'authentification! Vérifier votre login et mdp.'); // masques $capture_id = "<id>([0-9]+)<\/id>"; $capture_created_at = "<created_at>(.*)<\/created_at>"; $capture_text = "<text>(.*)<\/text>"; // captures preg_match("#$capture_id#iU", $buffer, $matches_id); preg_match("#$capture_created_at#iU", $buffer, $matches_created_at); preg_match("#$capture_text#iU", $buffer, $matches_text); // affichage des elements // echo "ID: ".$matches_id[0]."<br />\n"; // echo "Date: ".$matches_created_at[0]."<br />\n"; // echo "Texte: ".$matches_text[0]."<br />\n"; $id_publication = $matches_id[0]; $heure_publication = $matches_created_at[0]; $texte_publication = $matches_text[0]; // fin du code } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>XXXXXX.</title> <meta http-equiv="Content-Language" content="fr,ca"> <style type="text/css"> <!-- .Style2 {color: #FFFFFF; font-weight: bold; } --> </style> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="750" border="0" align="center"> <tr> <td><div align="center"> <div align="center"> <?php if (!isset($_POST['twitter_envoyer'])){ // affichage fichier ?> </div> <form id="form1" name="form1" method="post" action="twitter_envoyer.php"> <label> </label> <table width="85%" border="0"> <tr valign="baseline"> <td valign="middle" class="titre_table" ><div align="center">Poster un twitte</div></td> </tr> <tr> <td>Ce twitte sera posté sur le compte : <strong><?php echo $username_twitter ?></strong> attention de ne pas dépasser la longeur du champs ci-dessous</td> </tr> <tr> <td><div align="center"> <input class="Boite" name="message" type="text" id="message" size="100" /> </div></td> </tr> <tr> <td><div align="center"> <input class="bouton" type="submit" name="twitter_envoyer" id="envoyer" value="Poster sur twitter" /> </div></td> </tr> </table> <label></label> <label></label> <input type="hidden" name="MM_insert" value="form2" /> </form> <div align="center"> <table width="90%" border="0"> <tr valign="baseline"> <td valign="middle" class="titre_table" ><div align="center">Twitte Posté sur twitter</div></td> </tr> <tr> <td> <?php // lister tous les twittes // Remplissez votre login et motdepasse $username = $username_twitter; $password = $password_twitter; // Twitter API address $url = "http://twitter.com/statuses/user_timeline.xml?count=100&page=1"; // Set up et execute les procédures curl $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password"); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($curl_handle); // affiche les messages d'erreurs ou ferme la connexion if (curl_errno($curl_handle)) { print curl_error($curl_handle); } curl_close($curl_handle); // Check la connexion et retourne un message en cas d'erreur if (preg_match("#Could not authenticate you#iU", $buffer)) die ('Erreur d\'authentification! Vérifier votre login et mdp.'); // masques $capture_id = "<id>([0-9]+)<\/id>"; $capture_created_at = "<created_at>(.*)<\/created_at>"; $capture_text = "<text>(.*)<\/text>"; // captures preg_match_all("#$capture_id#iU", $buffer, $matches_id); preg_match_all("#$capture_created_at#iU", $buffer, $matches_created_at); preg_match_all("#$capture_text#iU", $buffer, $matches_text); // fin du code ?> </td> </tr> <tr> <td><table width="90%" border="1" align="center"> <?php $i=0; while ($i < count($matches_id, COUNT_RECURSIVE) ) { if (!empty ($matches_text[0][$i])){ $id_poste = $matches_id[0][$i]; $date_poste = $matches_created_at[0][$i]; $texte_poste = $matches_text[0][$i]; ?> <tr> <td width="5%"><form action="twitter_envoyer.php" method="post" name="form1" id="form1"> <input name="image" type="image" class="intranet_image" src="../icones/sup.gif" alt="Supprimer" width="15" height="15" /> <input type="hidden" name="MM_insert" value="form1" /> <input type="hidden" name="id_txitte_sup" value="<?php echo $id_poste; ?>" /> </form></td> <td width="15%"><?php echo $id_poste ?></td> <td width="15%"><?php echo $date_poste ?></td> <td width="65%"><div align="left"><?php echo $texte_poste ?></div></td> </tr> <?php } $i++; } ?> </table> <div align="center"></div></td> </tr> <tr> <td> </td> </tr> </table> <?php } ?> <?php if (isset($_POST['twitter_envoyer'])){ // affichage fichier ?> </div> <table width="41%" border="0" align="center"> <tr> <td height="64" class="header_table"><div align="center"> <p class="right"><?php echo $id_publication ?></p> <p class="right"><?php echo $heure_publication ?></p> <span class="right"><?php echo $texte_publication ?></span> <p class="right"> </p> <p class="right"> </p> <p class="right"> </p> </div></td> </tr> <tr> <td class="Tableau_corps"><div align="center"></div></td> </tr> </table> <div align="center"> <?php } ?> </div> <p align="center"> </p> </div></td> </tr> <tr> <td> </td> </tr> </table> <p align="center"> </p> </body> </html>
Bonjour,
La méthode avec Curl ne fonctionne plus depuis le 1er septembre 2010 car Twitter a désactivé l'authentification basique.
Il faut maintenant utiliser une méthode plus complexe : OAuth.
Voici un tuto simple expliquant une manière de faire :
http://yanncochard.com/tuto/envoyer-...th-sur-twitter