Text gets auto Tweeted while Media (image) does not

4 replies
Hello could someone please help me implement Twitter status updates.

I am using this ridiculously simple script to auto Tweet on behalf of a user.

PHP Code:
$image 'test.jpg';

// Insert your keys/tokens
$consumerKey 'xxx';
$consumerSecret 'xxx';
$OAuthToken 'xxx';
$OAuthSecret 'xxx';

// Full path to twitterOAuth.php (change OAuth to your own path) 
require_once('connect/twitter/twitteroauth.php');  
$params = array(     
    
'status' => $_REQUEST['content'],     
    
'media[]' => '@{$image}'
);  
// create new instance 
$tweet = new TwitterOAuth($consumerKey$consumerSecret$OAuthToken$OAuthSecret);  
// Send tweet 
$tweet->post('statuses/update'$params); 
Upon executing this code, text gets Tweeted on my twitter account however the image does not. I have been previously advised to only attempt tweeting local files and I was advised this is the proper way to specify the media[].

Why isnt this posting the image while its posting the text to twitter?

Please help I have been struggling with this for days now.
#auto #media #text #tweeted
  • Profile picture of the author mojojuju
    Try changing this:

    'media[]' => '@{$image}'

    to this:

    'media[]' => "@{$image}"
    Signature

    :)

    {{ DiscussionBoard.errors[8931294].message }}
    • Profile picture of the author shahriyar
      Here is a similar script you can try out, I am not sure if it post external image,
      http://www.pontikis.net/blog/auto_po...itter_with_php

      If it doesn't, you can use file_get_contents (binary safe) to download the image, save it locally and then post to using the local image path.
      {{ DiscussionBoard.errors[8931779].message }}
      • Profile picture of the author ahojvole
        Originally Posted by mojojuju View Post

        Try changing this:

        'media[]' => '@'

        to this:

        'media[]' => "@"
        Unfortunately changing apostrophes to quotes did not change its behaviour.

        Originally Posted by shahriyar View Post

        Here is a similar script you can try out, I am not sure if it post external image,
        How to Auto Post on Twitter with PHP

        If it doesn't, you can use file_get_contents (binary safe) to download the image, save it locally and then post to using the local image path.
        Thank you for suggestion. I tried several different variants however the Codebird library did not seem to work for me at all.

        Regarding the file_get_contents function, it does not seem to make any difference, because the image is being uploaded to Twitter locally anyway.

        I still dont understand why doesnt the original code work. Its very simple and there is very little space for error. I will try to update libraries that I use for OAuth and Twitter communication to make sure, everything is compatible with new Twitter 1.1 API version. Other than that I have ran out of ideas days ago.
        {{ DiscussionBoard.errors[8932518].message }}
        • Profile picture of the author ahojvole
          Any other ideas please? I havent had much luck still attempting this
          {{ DiscussionBoard.errors[8939989].message }}

Trending Topics