PHP "POST update_profile_background_image" does not update the image - raw image need ?


#1

Hi,

My first post, thank you for your support and cheerful welcome :slight_smile:

I am new to both Twitter API and PHP, but have managed (thanks to the information found on the Web) to successfully tweet (with image), retweet, update profile image but fail with profile background image update.

Looking on the net I have found many discussions and examples, but all of them use the ‘image’ => ‘@filename’ which is no more supported if I do understand correctly.
– when @ used, tmhOAuth states : Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class

I have tried to build a

          $image_curlfile = new CurlFile('C:\path\test.JPG', 'image/jpg', 'test.JPG');

… but don’t know how to provide this to ‘image’, googling this gives no result.

The API (https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image) states that the image must be “provided as raw multipart data, not a URL”. This is not clear to me even after looking on the web for hours, thus my call for help. Future responses will surely provide an update for update_profile_background_image calls.

I am using tmhOAuth, and make use of PHP through command lines, not a form.

Code extract :

      $code = $this->tmhOAuth->request(
                'POST', $this->tmhOAuth->url('1.1/account/update_profile_background_image'), 
                    array(
                        'image' => base64_encode(file_get_contents('C:\Users\Thomas\Desktop\Eric.JPG')),
                        'tile' => true,
                        'use'  => true,
                        'include_entities' => false,
                        'skip_status' => true
                    ),
                true, // use auth
                true  // multipart
        );

$code values to 200, but the profile background is not updated on twitter’s page.

Can you please share advice or piece of code which actually works at date (novembre 2013) ?

Many thanks,

Eric


#2

Hi,
Does anyone use “update_profile_background_image” with the new interface requiring raw data and could provide the code to pass the raw data please ?
Many thanks,
Eric


#3

I am happy to share the fix (basic though : the boolean parameter was not passed as a string…).
Enjoy your day

'image' => base64_encode(file_get_contents("$bg_image")), 'tile' => 'false', 'include_entities' => 'false', 'skip_status' => 'true', 'use' => 'true'

#4

Hi Eric,

The code what you have shared returns 500 as status code for me.

base64_encode(file_get_contents("$bg_image"))

Below code returns 200 as status code and other information. But the background image in profile is not updated. After the api call, if I access the profile_background_image_url browser saying (FF) can’t be displayed because it contains errors.

Help me to fix the issue.

Thanks in advance.

$params = [ 'image' => '@'.DOC_ROOT.'/assets/img/location_1.png;type=image/png;filename=location_1.png', 'use' => 'true' ]; $code = $tmhOAuth->request('POST', $tmhOAuth->url("1.1/account/update_profile_background_image.json"), $params, true, // use auth true // multipart );

#5

Hi. I’m getting the same issue. Have you fixed it?


#6

I am also having a problem with posting images to the update_profile_background_image endpoint, but only from certain locations.

I am using the following code:

$image = “/valid/path/to/image.png”;
$code = $tmh->request(
‘POST’,
$tmh->url(‘1.1/account/update_profile_background_image’),
array(
‘image’ => “@” . $image,
‘use’ => ‘true’
),
true, // use auth
true
); // multipart

var_dump($code);

I am getting a 200 response any where I run this code but the background image never updates. I am using the latest version of the tmh oauth library with valid api credentials. I am able to post a tweet with an image just fine from any of the servers.

I am only having an issue when I run this code from a server hosted with AWS to this endpoint: 1.1/account/update_profile_background_image

Monitoring the curl info from the servers, I am able to see that the image is sent to the twitter api with the request but it is never set as the background when sent from the AWS servers. From the other locations I have tried, it has worked just fine(using the exact same code). If I download the file from the server and use the md5 sum of the files to verify they match, I can upload the image manually and it is accepted and set as the background.

The pixel size and file size of the image are with in the requirements posted in the documentation. This code has also been in place since 1.1 was released and has suddenly stopped working in the past couple of weeks with no change to the code base.

Are any of you hosted with AWS? Have you had any luck with posting from other servers / locations? Possibly even found the issue and corrected it?


#7

I tested on 3 servers from US and EU, but no luck. I also found several other developers with the same problem.


#8

I got it work at Rackspacecloud (Region: Chicago) for now.


#9

With out changing any code, this has suddenly started to work. Just as randomly as when it stopped working.


#10

Hi,

On an other thread linked with images, I had it work with putting multipart=false.
This change made it work - maybe the libray I use is not fully working in all cases although it is supposed to be (tmhOAuth).

Have a try with multipart=false, and share your results please.

Eric