Twitter API - 更新个人资料
问题描述:
我正在查看Twitter API:http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0update_profileTwitter API - 更新个人资料
我想通过PHP更新我的个人资料。
特别是我的位置:旧金山,CA
我不是寻找什么特别的,只是一个调用XML,检查其内容,然后在合适的时候新的值写入的方式。
任何人都可以指向正确的方向吗?
答
public function updateProfile($name = null, $email = null, $url = null, $location = null, $description = null)
{
// validate parameters
if($name === null && $email === null && $url === null && $location === null && $description === null) throw new TwitterException('Specify at least one parameter.');
if($name !== null && strlen($name) > 40) throw new TwitterException('Maximum 40 characters allowed for name.');
if($email !== null && strlen($email) > 40) throw new TwitterException('Maximum 40 characters allowed for email.');
if($url !== null && strlen($url) > 100) throw new TwitterException('Maximum 100 characters allowed for url.');
if($location !== null && strlen($location) > 30) throw new TwitterException('Maximum 30 characters allowed for location.');
if($description !== null && strlen($description) > 160) throw new TwitterException('Maximum 160 characters allowed for description.');
// build parameters
if($name !== null) $aParameters['name'] = (string) $name;
if($email !== null) $aParameters['email'] = (string) $email;
if($url !== null) $aParameters['url'] = (string) $url;
if($location !== null) $aParameters['location'] = (string) $location;
if($description !== null) $aParameters['description'] = (string) $description;
// make the call
$response = $this->doCall('account/update_profile.xml', $aParameters, true);
// convert into xml-object
$xml = @simplexml_load_string($response);
// validate
if($xml == false) throw new TwitterException('invalid body');
// return
return (array) $this->userXMLToArray($xml, true);
}
答
curl -u user:password -d "location=San Francisco, CA" http://twitter.com/account/update_profile.xml
+0
然而,今年7月份Twitter将逐步实现这一简单授权,您需要使用OAuth。 .. – 2010-01-02 17:55:34
+1
都是人们醉酒上面的家伙问如何使用PHP – streetparade 2010-01-02 18:12:54
可不可以给我的,我怎么会用这样的想法? – CLiown 2010-01-02 17:49:44
不是之后你投下我的答案 – streetparade 2010-01-02 18:03:18
我没有投票它! – CLiown 2010-01-02 18:07:56