API aracılığıyla heyecan arka plan güncelleniyor

2 Cevap php

Ben Twitter'ın API aracılığıyla arka güncelleme biraz sorun yaşıyorum.

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

Ben cURL veya file_get_contents yoluyla ham verileri çekmeye çalıştığınızda, ben bu olsun ...

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.

2 Cevap

Tamam, bir URL'ye Twitter doğrudan değil, o kabul olmaz. Ben en iyi yolu yerel sunucuya görüntü indirmek ve daha sonra neredeyse bir formu yüklenme gibi Twitter bu üzerinden geçmek olduğunu tespit ettik biraz etrafa.

Aşağıdaki kodu deneyin ve bana ne olsun bildirin.

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

Eğer URL içeriğini kendiniz yüklemek, doğrudan veri göndermek gerektiği gibi Eh, hata iletisi verilir, bu sesler. Bunu denediniz mi?