代码之家  ›  专栏  ›  技术社区  ›  homework

通过API更新Twitter背景

  •  0
  • homework  · 技术社区  · 15 年前

    我在通过Twitter的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');
    

    当我试图通过cURL或file_get_内容提取原始数据时,我得到了这个。。。

    此服务器无法满足字段的要求。 期望:100继续,但我们只允许100继续期望。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Jon Skeet    15 年前

    好吧,给出了错误消息,听起来你应该自己加载URL的内容,然后直接发布数据。你试过了吗?

        2
  •  1
  •   jakeisonline    15 年前

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