twitterAPI1.1ã®è¿ä¿¡å¯¾å¿ã«ã¤ãã¦
ã©ãããåã®è¨äºã®ç¶ãã§ãã
ä»åã¯è¿ä¿¡é¨åã¨ãã®ä»ãããã£ã¼ã«ç»åã®å¤æ´APIã«ã¤ãã¦æ¸ãã¾ãã
10æ11æ¥ããã«ç¾è¡1ã®APIææ³ãªã©ãå¤ãã£ãããã§ãã
xmlã使ç¨ãã¦ããå ´åãurlã«apiã®ãã¼ã¸ã§ã³ãæè¨ãã¦ããªãã¨åããªãã¨ãã
ãã®æ©ä¼ã«1.1対å¿ãã¦ãã¾ãã¾ãããã
ã¾ããè¿ä¿¡é¨åã®å¯¾å¿ã§ãã
以åã®ããã°ã©ã ã§ã¯
$host = "http://twitter.com/statuses/mentions.xml"; //è¿ä¿¡ä¸è¦§ //ããä¸è¨ã«å¤æ´ $host = "https://api.twitter.com/1.1/statuses/mentions_timeline.json"; //è¿ä¿¡ä¸è¦§
ããã§xmlãjsonã«ãã¾ããjsonå½¢å¼ãªã®ã§ãã¼ã¹ã®ææ³ãå¤ãã¾ãã
//XMLæååããªãã¸ã§ã¯ãã«ä»£å ¥ãã $XML = simplexml_load_string($req); //ããä¸è¨ã«å¤æ´ //jsonæååããªãã¸ã§ã¯ãã«ä»£å ¥ãã $JSON = json_decode($req);
ã¹ã¯ãªããã®$XMLã®é¨åãç½®æã§$JSONã«å
¨ã¦å¤æ´ãã¦ä¸ããã
json_decodeã®é¢æ°ã使ããã®ã¯php5以éã§ããåºæ¥ãªãå ´åã¯ã確èªãã
ããã¦æ¬¡ã«ããããããã¨ããã§ãã
$XML->status[$i]->text; //ãã $JSON[$i]->text;
ã«ãªãã¾ããstatusã®é
ç®ãç¡ããªã£ãã¨ããããã§ãããã¹ã¦æ¸ãç´ãã¦ä¸ããã
ãããç½®æã§->statusãåé¤ããã°ããã§ããã
æå¾ã«ãå¤æ´ããã£ãé¨åã§ãã
ä»ã¾ã§çºè¨postã«ä»ä¸ãããidãåå¾ããããããæ¢ã«å¦çæ¸ã¿ã®é
ç®ãåæ¨é¸æãã¦ããã®ã§ãããå¤æ´ããããidã¨ããé
ç®ã¨id_strã¨ããé
ç®ã«ããããããã§ãã
ã¡ã³ã·ã§ã³ã®çºè¨ãåããªãã·ã§ã³ã®å¼æ°ãsince_idã¯id_strã使ãã¾ãã
//æçµçºè¨ãªãã©ã¤ã®idãä¿åãã¦ãé¨åãå é ã調ã¹ã¦â¦ $string = $XML->status[0]->id; //ä¸è¨ã«å¤æ´ //æçµçºè¨ãªãã©ã¤ã®idãä¿åãã¦ãé¨åãå é ã調ã¹ã¦â¦ $string = $JSON[0]->id_str;
ããã§æ£ããidãåå¾ãããã¯ãã§ãã
以ä¸ã§è¿ä¿¡é¨åãä»ã¾ã§éãåç¾ãããã¨æããã¾ãã
idé¨åã¯ç¹ã«ãæ´èµ°ã¨ç¹ãããããã®ã§ããã¯ã¢ããçãåãã¤ã¤æ
éã«ä½æ¥ãã¦ä¸ããã
ã¡ãªã¿ã«ç»åå¤æ´ã®é¢æ°ã¯urlã帰ãã ãã§OKã§ãã
https://api.twitter.com/1.1/account/update_profile_image.json
ãããã§ããã§ãããããã¿ãªãã楽ããbotã©ã¤ããã