PHP Classes

Unable to post image to twitter

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  How to Implement PHP ...  >  All threads  >  Unable to post image to twitter  >  (Un) Subscribe thread alerts  
Subject:Unable to post image to twitter
Summary:Unable to post image to twitter
Messages:10
Author:developer
Date:2014-10-01 15:11:42
 

  1. Unable to post image to twitter   Reply   Report abuse  
Picture of developer developer - 2014-10-01 15:11:42
Givinv following error

Error: it was not possible to retrieve the API call: 3 it was not possible to access the file php-oauth.png

  2. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-10-01 20:44:14 - In reply to message 1 from developer
The file must exist with that path in the same machine you are running PHP. Does the file exist?

  3. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of developer developer - 2014-10-07 12:54:00 - In reply to message 2 from Manuel Lemos
Sorry ! File path was not correct.

Thanks!

  4. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Kim Ball Kim Ball - 2015-03-31 21:11:22 - In reply to message 2 from Manuel Lemos
Is there a way to post an image from a remote url instead of a directory on the same server?

  5. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-04-01 02:36:25 - In reply to message 4 from Kim Ball
Do you want to attach a file with contents from a remote URL, or do you want to insert the URL of that file in the Twitter post message?

  6. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Kim Ball Kim Ball - 2015-04-01 13:43:38 - In reply to message 5 from Manuel Lemos
$media = "image.png"; //works perfect!
$media = "http://domain/image.png"; //This is what I need!

"https://api.twitter.com/1.1/statuses/update_with_media.json",
'POST', array('status'=>$text,
'media[]'=>$media),array(
'FailOnAccessError'=>true,
'Files'=>array('media[]'=>array()
), $osid,$user);


  7. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-04-01 21:42:18 - In reply to message 6 from Kim Ball
$media = "http://domain/image.png";

You can try the latest class version using a call like this:

$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update_with_media.json",
'POST', array(
'status'=>'This is a test tweet to evaluate the PHP OAuth API support to upload image files sent at '.strftime("%Y-%m-%d %H:%M:%S"),
'media[]'=>file_get_contents($media)
),
array(
'FailOnAccessError'=>true,
'Files'=>array(
'media[]'=>array(
'FileName'=>'image.png'
)
)
), $upload);

  8. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-04-01 21:53:26 - In reply to message 6 from Kim Ball
Sorry you also need to set the type of parameter to 'Data'

$media = "http://domain/image.png";
$success = $client->CallAPI(
"https://api.twitter.com/1.1/statuses/update_with_media.json",
'POST', array(
'status'=>'This is a test tweet to evaluate the PHP OAuth API support to upload image files sent at '.strftime("%Y-%m-%d %H:%M:%S"),
'media[]'=>file_get_contents($media)
),
array(
'FailOnAccessError'=>true,
'Files'=>array(
'media[]'=>array(
'Type'=>'Data',
'FileName'=>'image.png'
)
)
), $upload);

  9. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Kim Ball Kim Ball - 2015-04-11 14:58:17 - In reply to message 8 from Manuel Lemos
I am still not able to upload the image. Can you explain what should be included in the $upload parameter? in all other examples you use the $user parameter. I do not find any reference to $upload in your API code.

  10. Re: Unable to post image to twitter   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-04-13 04:10:10 - In reply to message 9 from Kim Ball
As explained in the documentation, that last parameter is a variable that is passed by reference to return the response of the request.

You can name it the way you want. In that case, I called it $upload because you are uploading some data, but you may choose some other name.