【问题标题】:Twitter API - Update ProfileTwitter API - 更新个人资料
【发布时间】:2010-01-02 17:35:14
【问题描述】:

我正在查看 Twitter API:http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0update_profile

我想通过 PHP 更新我的个人资料。

特别是我的位置:加利福尼亚州旧金山

我不是在寻找任何花哨的东西,只是一种调用 XML、检查其内容,然后在适当的情况下写入新值的方法。

谁能指出我正确的方向?

【问题讨论】:

    标签: php twitter


    【解决方案1】:
    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);
        }
    

    【讨论】:

    • 你能告诉我如何使用它吗?
    • 好的,首先你需要一个推特库,如果你愿意,我可以给你我的推特库code.google.com/p/twitter-boot你会找到它code.google.com/p/twitter-boot/source/browse/trunk/twitter-bot/…这里把它包含在你的脚本中看看我写给你的推特机器人会找到很多例子
    • 我想你在下面的 cmets 中被否决了,但是谢谢你的帮助。
    • 如果您对我写的 bot 谷歌代码有疑问,欢迎您发送邮件给我 wyde16@gmail.com
    【解决方案2】:
    curl -u user:password -d "location=San Francisco, CA" http://twitter.com/account/update_profile.xml
    

    【讨论】:

    • 然而今年 7 月 Twitter 将逐步淘汰这种简单的授权,您需要使用 OAuth...
    • 所有人都喝醉了上面的人问如何使用php来做到这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 2015-03-04
    • 2012-09-15
    • 1970-01-01
    相关资源
    最近更新 更多