通过API更新Twitter的背景 [英] Updating Twitter background via API

查看:163
本文介绍了通过API更新Twitter的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小麻烦通过Twitter的API更新的背景。

  $ target_url =htt​​p://www.google.com/logos/11th_birthday.gif;
$ CH = curl_init();
curl_setopt($ CH,CURLOPT_HTTPHEADER,阵列('期待:'));
curl_setopt($ CH,CURLOPT_USERAGENT,$的userAgent);
curl_setopt($ CH,CURLOPT_URL,$ target_url);
curl_setopt($ CH,CURLOPT_FAILONERROR,真正的);
curl_setopt($ CH,CURLOPT_FOLLOWLOCATION,真正的);
curl_setopt($ CH,CURLOPT_AUTOREFERER,真正的);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);
curl_setopt($ CH,CURLOPT_TIMEOUT,10);
$ HTML = curl_exec($ CH);$内容= $&用于─GT; OAuthRequest('http://twitter.com/account/update_profile_background_image.xml',阵列('profile_background_image_url'=> $ HTML),'POST');

当我尝试通过卷曲的file_get_contents或拉的原始数据,我得到这个...


  

    

预期失败的预期要求标题的预期
    现场不能用此服务器来满足。
    送客户
        期望:100-继续,但我们只允许100-继续期望


  

解决方案

OK,你可以不是直接Twitter的一个URL,它不会接受这一点。环顾了一下,我发现,最好的办法是将图像下载到本地服务器,然后传递到微博几乎像一个形式上传。

请尝试以下code,并让我知道你会得到什么。

  //从我们想要抓住外部(或内部)服务器的URL
$ URL ='http://www.google.com/logos/11th_birthday.gif';//我们要抓住这个文件名,除非你想创建自己的
$文件名=基名($网址);//这是我们将拯救我们的新文件。与路径替换的localPath您想保存文件,即WWW /家庭/内容/ my_directory /
$ newfilename ='的localPath。 $文件名;//复制过来,PHP将处理开销。
副本($网址,$ newfilename);//现在它的OAuth时间......手指穿过!
$内容= $&用于─GT; OAuthRequest('http://twitter.com/account/update_profile_background_image.xml',阵列('profile_background_image_url'=> $ newfilename),'POST');//回声的东西,所以你知道它经历
打印完成;

I'm having a little trouble updating backgrounds via Twitter's API.

$target_url = "http://www.google.com/logos/11th_birthday.gif";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);

$content = $to->OAuthRequest('http://twitter.com/account/update_profile_background_image.xml', array('profile_background_image_url' => $html), 'POST');

When I try to pull the raw data via cURL or file_get_contents, I get this...

Expectation Failed The expectation given in the Expect request-header field could not be met by this server. The client sent Expect: 100-continue but we only allow the 100-continue expectation.

解决方案

OK, you can't direct Twitter to a URL, it won't accept that. Looking around a bit I've found that the best way is to download the image to the local server and then pass that over to Twitter almost like a form upload.

Try the following code, and let me know what you get.

// The URL from an external (or internal) server we want to grab
$url = 'http://www.google.com/logos/11th_birthday.gif';

// We need to grab the file name of this, unless you want to create your own
$filename = basename($url);

// This is where we'll be saving our new file to. Replace LOCALPATH with the path you would like to save the file to, i.e. www/home/content/my_directory/
$newfilename = 'LOCALPATH' . $filename;

// Copy it over, PHP will handle the overheads.
copy($url, $newfilename);

// Now it's OAuth time... fingers crossed!
$content = $to->OAuthRequest('http://twitter.com/account/update_profile_background_image.xml', array('profile_background_image_url' => $newfilename), 'POST');

// Echo something so you know it went through
print "done";

这篇关于通过API更新Twitter的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆