As a part of the application. I want users to share the image generated using the app with some text of their choice.
I went on to use a Twitter Library twitteroauth by natefanaro which supports to tweet images with text via Twitter API.
https://github.com/natefanaro/twitteroauth
According to the Library one can send a tweet with text by the method below.
$connection->post('statuses/update', array('status' =>"Test Tweet"));
When i tried with a post a tweet along with a image and text. It ain't works.Here's the code to post image with some text.
$connection->post('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
PS: All i need is to let the users of the app share the image to their twitter timeline. Help me if there's a better method to do the same.
Change:
$connection->post('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
to:
$connection->upload('statuses/update_with_media', array('status' => 'Test Tweet with Img from App', 'media[]'=>'img03.jpg'));
Notice the change from "post" to "upload"
Related
I am working on a Twitter app and I want to find a way to link directly to a retweet.
For example. If user A makes a tweet, and user B retweets it, I want a URL that will take us to user B's profile where the retweet is displayed. What is that unique URL?
I recently needed to get a link to an arbitrary retweet that was too old for the search feature to work.
Here's what I did:
Open the Network Monitor
Visit the timeline of the retweeter
Scroll until you find the retweet
Look at the Network Monitor, open the latest request to the endpoint /UserTweets
Either
go to the "Response" tab and sift through its JSON manually to get the id_str to craft the URL:
or, paste the following into the Console, then right-click on the response, “Copy…Response”, and return to the console to press Enter:
UserTweets = JSON.parse(prompt("Paste the copied Response data:"));
// get the output from that endpoint,
UserTweets
// dig through the packaging,
['data']['user']['result']['timeline_v2']['timeline']['instructions']
// filter out "pinned tweets" metadata,
.filter(cmd => cmd['type'] == "TimelineAddEntries")
// de-batch,
.flatmap(cmd => cmd['entries'])
// filter out "cursor" metadata,
.filter(entry => entry['content']['entryType'] == "TimelineTimelineItem" )
// then dig through a bunch more layers of packaging,
.map(entry => entry['content']['itemContent']['tweet_results']['result'])
// munge the tweets into a more-usable format,
.map(tweet => ({user: tweet['core']['user_results']['legacy'], tweet: tweet['legacy']}))
// filter out non-retweets,
.filter(({tweet}) => tweet['retweeted_status_result'])
// extract just the RT text and URL of the retweet itself,
.map(({user, tweet}) => ({url: `https://twitter.com/${encodeURIComponent(user['screen_name'])}/status/${encodeURIComponent(tweet['id_str'])}`, text: tweet['full_text']}))
// print results.
.forEach(({url, text}) => console.log(url, text))
…et voilà:
https://twitter.com/ThePSF/status/1398372497741946884
Internally, all Retweets are simply special Tweets. This means each Retweet also has an ID (which is stored on id and id_str at the root of the Tweet object). For proof, here's a Retweet from the Twitter Retweets account.
If you're using Tweet Streams (e.g. statuses/filter), you'll be able to pick up this ID from the returned Tweet object of the retweet. From the ID, you can just build a normal Twitter link with https://twitter.com/<username>/status/<retweet id>. Assuming your Retweet object is named retweet, the correct link would be (in JavaScript) `https://twitter.com/${retweet.user.screen_name}/status/${retweet.id_str}`.
If the Retweet is fairly recent, you can do a status search (search/tweets) on the user's profile (i.e. you have to set the q parameter to from:<username>) to find the Retweet. You'll most likely have to cross check the ID of the Tweet you want and the ID of the Retweet you're looking for to be sure, though.
If you're trying to get the Retweet ID of an old Tweet, however, you might have to use Twitter's Premium APIs, which are paid.
JamesTheAwesomeDude's answer worked for me with some light modifications for the new twitter API:
UserTweets = { /*PASTE HERE*/ }
// .timeline changed to .timeline_v2
UserTweets.data.user.result.timeline_v2.timeline.instructions
.filter(cmd => cmd['type'] == "TimelineAddEntries")
.map(cmd => cmd['entries']).flat()
.filter(entry => entry['content']['entryType'] == "TimelineTimelineItem" )
.map(entry => entry['content']['itemContent']['tweet_results']['result'])
// .user changed to .user_results.result
.map(tweet => [tweet['core']['user_results']['result']['legacy'], tweet['legacy']])
.filter(([user, tweet]) => tweet['retweeted_status_result'])
.map(([user, tweet]) => [`https://twitter.com/${user['screen_name']}/status/${tweet['id_str']}`, tweet['full_text']])
.forEach(([url, rt_text]) => console.log(url, rt_text))
I've created a Whatsapp chat bot that collects various user information but I am unable to collect an image that a user sends. How can I do this? Is it a matter of using the right Field type, which I've tried doing but none of the default field's apply to images? Please help if anyone knows of a solution.
Heyooo. 👋 Twilio Developer Evangelist here.
If a User sends an image via Whatsapp the image URL will be available in the sent webhook. You can have a look at the payload the webhook includes:
body: {
MediaContentType0: 'image/jpeg',
SmsMessageSid: 'MM9...',
NumMedia: '1',
SmsSid: 'MM9...',
SmsStatus: 'received',
Body: '',
To: 'whatsapp:+141...',
NumSegments: '1',
MessageSid: 'MM9bc...',
AccountSid: 'ACa34...',
From: 'whatsapp:+49176...',
MediaUrl0: 'https://api.twilio.com/2010-04-01/Accounts/ACa34bb5d3c305d08ae1308786f4d79b72/Messages/MM9bc3...',
ApiVersion: '2010-04-01'
}
You'll find the NumMedia and MediaUrl0 property which includes the URL of the sent image. You can then download these images and do whatever you like with them.
To retrieve the image after the message and webhook were sent you can have a look at the MediaResource Docs. You can fetch media also programmatically with something along the following lines:
client.messages('MM...')
.media('ME...')
.fetch()
.then(media => console.log(media.contentType));
In case you're using Studio you can have a look at this tutorial which handles Whatsapp Media with a fun use case.
Let me know if that helps. 😊
(It's hard to give more advice because I'm not sure what you're trying to do.)
I am creating a twitter share button that a user can click but I also want to attach an image to the tweet.
I am uploading the image to Twitter using the API so have the media ID available.
Is there a way to get the URL from this ID so I can attatch it to a Twitter Intent link?
Or can I only use this Media ID with the API to post a tweet for an authenticated user?
I am trying to attatch a Twitter hosted Image to a Share button so that anybody can post it to their Twitter feed
Before you can attach the image to a tweet, you would need to upload the image to twitter first. I think you are already doing this using the endpoint media/upload
Reference:
https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload
Once this is done issue another POST request to the endpoint statuses/update with parameters 'status' and 'media_ids'. Twitter expects a comma separated list of media_ids. You already have this in the object returned by media/upload endpoint.
Reference:
https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
The object returned in the above call has the url for each media uploaded under the property entities.
This is an excerpt from how I did using PHP and abrahamoauth library. $connection is the twitter connection object.
$media = $connection->upload('media/upload', array('media' => $_FILES["tweet_image_file"]["tmp_name"]));
$parameters = array(
'status' => '',
'media_ids' => implode(',', array($media->media_id_string)),
);
$result = $connection->post('statuses/update', $parameters);
//$image_url = $result->entities->media[0]->media_url; //stopped working from July 2015
$image_url = $result->entities->media[0]->url;
I used the Facebook PHP SDK to upload a YouTube Video in the FB user wall.
I used the "source" option in "/USER_ID/feed/" of Graph API.
USER_ID is the logged in user's Facebook ID.
My code was working fine.
But Facebook made some changes in their API and the code is not working anymore.
Only the Youtube video image is showing but the Youtube video is not playing in facebook.
My code looks like this:-
$params = array(
'access_token' => $fbToken,
'message' => $name.' has shared a Vhybe',
'link' => $link,
'name' => 'Vhybe Social',
'caption' => $title,
'description' => $content
);
$sourceUrl = "https://www.youtube.com/v/".$videoId;
$imageUrl = "http://i4.ytimg.com/vi/".$videoId."/default.jpg";
$params['source'] = $sourceUrl;
$params['picture'] = $imageUrl;
$result = $facebook->api(
'/'.$userId.'/feed/',
'POST',
$params
);
I tried the "Graph API explorer" tool from the Facebook developer tools section
URL => https://developers.facebook.com/tools/
But i am getting the same results.
If the above process to upload Youtube video to user wall has been deprecated can you please suggest me an alternate process.
Thanks in advance.
Sincerely,
Sourav Mukherjee
Well the above code is working fine again.
I did not make any changes in my code.
Looks like Facebook corrected their own issue.
Sincerely,
Sourav Mukherjee
I've started to play with the Koala gem for a RoR app. I've already got permission from the user to publish to their stream
After this line
graph = Koala::Facebook::GraphAPI.new(#facebook_cookies["access_token"])
to post to the stream, I can do a
graph.put_object("me", "feed", "I am writing to my wall")
The above works, but how do I include an image like http://example.com/foo.jpg as part of the update? I tried reading up the Stream Attachments but without a lot of luck. Does anyone have some sample code?
You can use something like:
options = {
:message => "I am writing to my wall",
:picture => "http://example.com/foo.jpg"
}
graph.put_object(facebook_uid, "feed", options)