Twitter API -> updating profile bg image with php

后端 未结 4 1187
故里飘歌
故里飘歌 2021-01-01 07:03

So far I have been trying to update the twitter profile bg image thr the twitter api with php... and without success

Many examples on the web, including this one:

4条回答
  •  青春惊慌失措
    2021-01-01 07:58

    I think you're using the CURLOPT_POSTFIELDS method wrong. You need to put and @ sign in front of the full path to the file according to the documentation for curl PHP. You are not supposed to output the whole file contents.

    The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. This can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.

    This is an example from the documentation.

     'Foo', 'file' => '@/home/user/test.png');
    
    curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    
    curl_exec($ch);
    ?>
    

    I hope this helps.

提交回复
热议问题