Tweet an animated GIF programmaticaly


#1

Hi,
On my website, I generate animated GIFs that users can watch and share. I would like them to, by a simple click of a button, tweet this GIF with a description and hashtags. I have a custom button that refer to “https://twitter.com/intent/tweet” with my parameters.

Here are the codes :
(php code)


		Twitter

And the file at the url $wayToGif (html file) :



	Test_swipe_8
	
	
	
	
	
	




Actually, this give me a card with a static image (the first of my GIF).
I would like to generate the same card but with my animated gif, and not a static image.
I think a have to use REST API, but i don’t know how.

Please, can anyone guide me in using REST API or give me another way to do?


#2

Yes, you need to use the REST API. Since you aren’t familiar with it, you may be best off using something like @abraham’s library: https://github.com/abraham/twitteroauth


#3

Thank you for your fast answer.

Is it possible to only use abraham’s library to upload my animated gif and use an URL or metaData to tweet it ?
On the other hand, I don’t understand how to get user acces to handle him to tweet as himself (the token and token_secret I supposed).


#4

You would need to implement a sign in with Twitter flow in order to have the user authenticate to their Twitter account.


#5

Read through https://twitteroauth.com/, mostly the “Authorization Flow” section and then the “Media” section.


#6

It seems that I have a problem with the libraries. I’ve identified the problem in the oauth/request. The library is reachable, I can create TwitterOAuth object…

Here is the php code :

$connexion =  new TwitterOAuth($CONSUMER_KEY, $CONSUMER_KEY_SECRET);  // My apps keys
$oauth_callback = urlencode($call_back_url);      //$call_back_url = https://mydomain.fr/node/edit

$tok = twitter_get_user_token();

function twitter_get_user_token(){
	$request_token = $connexion->oauth('oauth/request_token', array('oauth_callback' => $oauth_callback));     <--- Here is the problem
	return $request_token; 
}

Any ideas ?

print_r($connexion) give me this :

Abraham\TwitterOAuth\TwitterOAuth Object ( [response:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Response Object ( [apiPath:Abraham\TwitterOAuth\Response:private] => [httpCode:Abraham\TwitterOAuth\Response:private] => 0 [headers:Abraham\TwitterOAuth\Response:private] => Array ( ) [body:Abraham\TwitterOAuth\Response:private] => Array ( ) [xHeaders:Abraham\TwitterOAuth\Response:private] => Array ( ) ) [bearer:Abraham\TwitterOAuth\TwitterOAuth:private] => [consumer:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\Consumer Object ( [key] => [secret] => [callbackUrl] => ) [token:Abraham\TwitterOAuth\TwitterOAuth:private] => [signatureMethod:Abraham\TwitterOAuth\TwitterOAuth:private] => Abraham\TwitterOAuth\HmacSha1 Object ( ) [timeout:protected] => 5 [connectionTimeout:protected] => 5 [decodeJsonAsArray:protected] => [userAgent:protected] => TwitterOAuth (+https://twitteroauth.com) [proxy:protected] => Array ( ) [gzipEncoding:protected] => 1 )

#7

I finally found where my error came from.

In my call

	$request_token = $connexion->oauth('oauth/request_token', array('oauth_callback' => $oauth_callback));     <--- Here is the problem

TwitterOAuth’s function oauth() throw me an error that I wasn’t handling.

 if ($this->getLastHttpCode() != 200) {
    throw new TwitterOAuthException($result);
}

After some research, it seems that my Apps can’t get a connection with twitter’s API.

I finaly choose an other way, using only meta data with my code in the first post :

My button (php code) :

''.
		'Twitter' .
'';

And my display (html code) :


	
		You all know what is it
		
		
		
		
		
		
	
	
		
	

Thank you for your help.


#8

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.