2009-09-27 4 views
0

Twitter의 API를 통해 배경을 업데이트하는 데 약간의 문제가 있습니다. 내가 말림 또는 file_get_contents를 통해 원시 데이터를 가져하려고하면API를 통해 Twitter 배경 업데이트하기

$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'); 

, 나는

기대 될 수없는 예상 요청 헤더 필드에 주어진 기대를 실패 ...이 얻을 이 서버가 만났습니다. 클라이언트가 을 보냈습니다. 기대 : 100- 계속하지만 100- 계속 기대 만 허용합니다. 당신이 URL의 내용을 직접로드하고 데이터를 직접 게시해야처럼

답변

1

좋습니다, 트위터를 URL로 보낼 수는 없지만 허용하지는 않습니다. 조금만 둘러 보니 가장 좋은 방법은 이미지를 로컬 서버에 다운로드 한 다음 양식 업로드와 거의 같이 Twitter에 전달하는 것입니다.

다음 코드를 시도해보고 내가 얻은 것을 알려주십시오.

// 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"; 
+2

원본 코드는 실제로 ''profile_background_image '=>'URL_HERE''URL_HERE이 실제 데이터 여야 함을 나타냅니다. 따라서 OAUTH 요청을하기 전에 PHP cURL을 사용하여 이미지 URL에서 이미지 데이터를 긁어내어 profile_background_image 옵션 내에 배치해야합니다. – jakeisonline

+0

PHP cURL에 대한 경험이 있습니까? 그렇지 않다면 나는 확실히 올바른 방향으로 당신을 가리킬 수 있지만 두려운 약간의 학습 곡선이있을 것입니다 – jakeisonline

+0

나는 이것을 실제로 시험하고 있습니다. 실제로 통과 된 것을 살펴보고 알려 드리겠습니다. – jakeisonline

1

글쎄, 오류 메시지 감안할 때, 그것은 소리. 너 그거 해봤 니?

관련 문제