Get video from tweet using Twitter API - api

I am trying to use the Twitter API to import a video from a given tweet. However, when I use the statuses/show endpoint, it doesn't return any extended entity for the video as it would an image, but instead returns a url entity linking to some video container embed with a video player containing an obscure link to the video.
Here is an example:
I am trying to import the tweet at https://twitter.com/NHL/status/633987786018717696
Using the Twitter API's statuses/show endpoint and the tweet id, I get this response:
{
"created_at": "Wed Aug 19 13:04:01 +0000 2015",
"id": 633987786018717700,
"id_str": "633987786018717696",
"text": "The offseason has us missing all of our fans, even the wacky ones... especially the wacky ones. #IsItOctoberYet?\nhttps://t.co/v4UGDQpa61",
"source": "Twitter Web Client",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 50004938,
"id_str": "50004938",
"name": "NHL",
"screen_name": "NHL",
"location": "30 cities across U.S. & Canada",
"description": "The official source of everything you need and want to know from the National Hockey League. Read before tweeting us: http://t.co/JlyVXSpqMn",
"url": "http://t.co/VI8RlwuVr9",
"entities": {
"url": {
"urls": [
{
"url": "http://t.co/VI8RlwuVr9",
"expanded_url": "http://www.NHL.com",
"display_url": "NHL.com",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": [
{
"url": "http://t.co/JlyVXSpqMn",
"expanded_url": "http://nhl.com/socialmediapolicy",
"display_url": "nhl.com/socialmediapol…",
"indices": [
118,
140
]
}
]
}
},
"protected": false,
"followers_count": 4130811,
"friends_count": 2646,
"listed_count": 18479,
"created_at": "Tue Jun 23 15:24:18 +0000 2009",
"favourites_count": 909,
"utc_offset": -14400,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"verified": true,
"statuses_count": 87436,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": true,
"profile_background_color": "000000",
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/378800000139631457/fd-xWa9G.jpeg",
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/378800000139631457/fd-xWa9G.jpeg",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/534776558238437376/yxrm83O7_normal.jpeg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/534776558238437376/yxrm83O7_normal.jpeg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/50004938/1435502670",
"profile_link_color": "040CDE",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "2E2E2E",
"profile_text_color": "0F5A80",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": false,
"following": true,
"follow_request_sent": false,
"notifications": false
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 865,
"favorite_count": 1342,
"entities": {
"hashtags": [
{
"text": "IsItOctoberYet",
"indices": [
96,
111
]
}
],
"symbols": [],
"user_mentions": [],
"urls": [
{
"url": "https://t.co/v4UGDQpa61",
"expanded_url": "https://amp.twimg.com/v/2a0210d1-4d39-4665-a749-ea34f8efef08",
"display_url": "amp.twimg.com/v/2a0210d1-4d3…",
"indices": [
113,
136
]
}
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"possibly_sensitive_appealable": false,
"lang": "en"
}
Upon following the URL, the source of the video tag is https://amp.twimg.com/amplify-web-player/prod/source.html?vmap_url=https%3A%2F%2Famp.twimg.com%2Fprod%2Fmultibr_v_1%2Fvmap%2F2015%2F08%2F20%2F13%2F609fc2af-1d06-4894-80be-1c231f97557a%2Fa69baa90-58de-4d1d-b2dc-2c3ef1ab9b35.vmap&duration=91.958&image_src=https%3A%2F%2Famp.twimg.com%2Fprod%2Fdefault%2F2015%2F08%2F20%2F13%2Fe8f0b317-ba48-4cec-bf2c-da4598e2b46b_poster-67227.jpg&content_id=609fc2af-1d06-4894-80be-1c231f97557a&page=amplify_card
How do I extract this video file from the tweet if they do not supply an external_entity for it?

The Twitter API has now changed and the videos are stored in the extended_entities object. There could be multiple sources depending on bitrate. This is how to retrieve the one with the highest bitrate:
var bitrate = 0;
var hq_video_url;
for (var j=0; j<tweet.extended_entities.media[0].video_info.variants.length; j++) {
if (tweet.extended_entities.media[0].video_info.variants[j].bitrate) {
if (tweet.extended_entities.media[0].video_info.variants[j].bitrate > bitrate) {
bitrate = tweet.extended_entities.media[0].video_info.variants[j].bitrate;
hq_video_url = tweet.extended_entities.media[0].video_info.variants[j].url;
}
}
}

Workaround for GIFs here!
In Twitter API V2, it is not possible to fetch GIF and video URLs currently. I know it is too silly. But one workaround is to fetch the preview image of the content and construct the media URL by hand.
Let's say we want to get GIF URL of the following tweet via V2 API: https://twitter.com/FloodSocial/status/870042717589340160
When we fetch the tweet with the following URL
https://api.twitter.com/2/tweets/870042717589340160?tweet.fields=attachments,author_id,created_at,entities,id,text&media.fields=preview_image_url,url&expansions=attachments.media_keys (with your bearer token of course), you will see that the response includes a preview_image_url with https://pbs.twimg.com/tweet_video_thumb/DBMDLy_U0AAqUWP.jpg
So here we can extract the DBMDLy_U0AAqUWP part from the URL, and construct the real GIF URL manually where it should be https://video.twimg.com/tweet_video/DBMDLy_U0AAqUWP.mp4
There you go. Only you need to write the extractor function.

When using statuses/show endpoint , add this option tweet_mode:'extended' to get the extended_entities object.
This path in the response will have video urls : extended_entities.media[0].video_info.variants
Example:
[
{
content_type: 'application/x-mpegURL',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
},
{
bitrate: 832000,
content_type: 'video/mp4',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
},
{
bitrate: 256000,
content_type: 'video/mp4',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
}
]

Well, depending on what platform you're using...
Connect to the URL directly
Consume the binary video data
Pump the binary data (e.g., a byte stream) through some widget that will display it.
The specifics on how to do this will vary greatly based on what platform & language(s) you are using.

Related

is there any rest API in bitbucket which can download the file at particular commit?

I know about this API
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}?at={commitId}
But with this API for binary files we get this response
{
"binary": true,
"path": {
"components": [
"src",
"log-output.7z"
],
"parent": "src",
"name": "log-output.7z",
"extension": "7z",
"toString": "src/log-output.7z"
}
}
For text files we get this response
{
"lines": [
{
"text": "abcd"
}
],
"start": 0,
"size": 1,
"isLastPage": true
}
I can re-create files with API response for text but is there any way to download the binary file or to get their size ?

How to store JSON data in a meaningful way in Oracle

Using Twitter API, I can get tweets like this :
{
"coordinates": null,
"created_at": "Mon Sep 24 03:35:21 +0000 2012",
"id_str": "250075927172759552",
"entities": {
"urls": [
],
"hashtags": [
{
"text": "freebandnames",
"indices": [
20,
34
]
}
],
"user_mentions": [
]
},
"in_reply_to_user_id_str": null,
"contributors": null,
"text": "Aggressive Ponytail #freebandnames",
"metadata": {
"iso_language_code": "en",
"result_type": "recent"
},
"retweet_count": 0,
"profile_background_color": "C0DEED",
"verified": false,
"geo_enabled": true,
"time_zone": "Pacific Time (US & Canada)",
"description": "Born 330 Live 310",
"default_profile_image": false,
"profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png",
"statuses_count": 579,
"friends_count": 110,
"following": null,
"show_all_inline_media": false,
"screen_name": "sean_cummings"
},
"in_reply_to_screen_name": null,
"source": "Twitter for Mac",
"in_reply_to_status_id": null
}
You can see that this data is perfect for MongoDB, you can easily write the data to there. I want to store this data on an SQL db like Oracle. I don't know how to store nested parts like :
"entities": {
"urls": [
],
"hashtags": [
{
"text": "freebandnames",
"indices": [
20,
34
]
}
],
"user_mentions": [
]
Can you tell me how I should write such properties on Oracle? Should I create a new table for each nested property(which I am unwilling to do) or is there another way? Is there a magical such that I can store all Tweet data in one place like it's done on NoSQL? Thanks.

Camera Remote API for Sony Ilce-7 Cannot change to "Contents Transfer" mode

I have been able to get my a-7 camera to take pictures by using the api. However I am stuck trying to transfer those images. By following the documentation I called the setCameraFunction to change it to contents transfer mode using the json below:
{"method":"setCameraFunction","params":["Contents Transfer"],"id":1,"version":"1.0"}
However the camera always returns with:
{"id":1,"error":[1,"Not Available Now"]}
Below is the output of the sequence I use to take the image (5 sec pause between each call):
Request: {"method":"startRecMode","params":[],"id":1,"version":"1.0"}
Response: {"result":[0],"id":1}
Request: {"method":"getAvailableShootMode","params":[],"id":1,"version":"1.0"}
Response: {"result":["still",["still"]],"id":1}
Request: {"method":"actTakePicture","params":[],"id":1,"version":"1.0"}
Response: {"result":[["http:\/\/192.168.122.1:8080\/postview\/pict20170707_003048_0.JPG"]],"id":1}
Request: {"method":"stopRecMode","params":[],"id":1,"version":"1.0"}
Response: {"result":[0],"id":1}
Request: {"method":"getStorageInformation","params":[],"id":1,"version":"1.0"}
Response: {"id":1,"error":[1,"Not Available Now"]}
Request: {"method":"setCameraFunction","params":["Contents Transfer"],"id":1,"version":"1.0"}
Response: {"id":1,"error":[1,"Not Available Now"]}
Sometimes the getStorageInformation returns with:
{
"result": [
[
{
"storageDescription": "Storage Media",
"numberOfRecordableImages": 3275,
"storageID": "Memory Card 1",
"recordTarget": true,
"recordableTime": -1
}
]
],
"id": 1
}
However trying to change to content mode always yields a "Not Available Now".
I have been able to access the preview image using the url generated by the actTakePicture function however this is a low resolution image and it won't work for our application.
I have also tried not calling the "stopRecMode" function before trying to enter "Contents Transfer" mode but it made no difference.
Output of the "getEvent" function before trying to enter Contents Transfer mode:
{
"result": [
{
"type": "availableApiList",
"names": [
"getVersions",
"getMethodTypes",
"getApplicationInfo",
"getAvailableApiList",
"getEvent",
"startRecMode",
"stopRecMode"
]
},
{
"cameraStatus": "NotReady",
"type": "cameraStatus"
},
null,
{
"type": "liveviewStatus",
"liveviewStatus": false
},
null,
[],
[],
null,
null,
null,
[],
null,
{
"cameraFunctionCandidates": [
"Contents Transfer",
"Remote Shooting"
],
"type": "cameraFunction",
"currentCameraFunction": "Remote Shooting"
},
null,
null,
null,
null,
null,
null,
{
"postviewImageSizeCandidates": [
"2M"
],
"type": "postviewImageSize",
"currentPostviewImageSize": "2M"
},
null,
{
"shootModeCandidates": [
"still"
],
"type": "shootMode",
"currentShootMode": "still"
},
null,
null,
null,
null,
null,
{
"fNumberCandidates": [],
"type": "fNumber",
"currentFNumber": "--"
},
null,
null,
null,
null,
{
"type": "shutterSpeed",
"shutterSpeedCandidates": [],
"currentShutterSpeed": "1/60"
},
{
"type": "whiteBalance",
"currentColorTemperature": -1,
"checkAvailability": true,
"currentWhiteBalanceMode": "Auto WB"
},
null
],
"id": 1
}
Other information:
Upgraded the camera to the latest firmware (version 3.20), installed the latest Smart Remote Control App (version 4.30).
I'm totally stuck here, any advice would be awesome.
Thanks
I was able to resolve the issue and thought I'd post it here in case it helps someone else.
Instead of using the "Contents Transfer" mode, what I had to do is use the "setPostviewImageSize" and set the preview image to original. With that changed the url returned by "actTakePicture" will be to the image just taken and the size of the image will be the full resolution, 6000x4000 in this case.
Here is the json for the setPostviewImageSize request:
{
"method": "setPostviewImageSize",
"params": [
"Original"
],
"id": 1,
"version": "1.0"
}

Instagram API and Pagination

I can't get all images using Instagram API, Pagination seems to be working somehow different and I can't understand it yet
I use request:
https://api.instagram.com/v1/users/self/media/recent?access_token=TOKEN
and can get first 20 photos:
...
{
"attribution": null,
"tags": [
"beautiful",
"instalife",
"picoftheday",
"beauty",
"instalike",
"gf",
"traveling",
"instatravel",
"vsco",
"tourism",
"\u0438\u0441\u043f\u0430\u043d\u0438\u044f",
"travelphoto",
"vscogood",
"instafollow",
"travel",
"\u0433\u0440\u0430\u043d\u0430\u0434\u0430",
"amazing",
"vscocam",
"followme",
"photooftheday"
],
"type": "image",
"location": null,
"comments": {
"count": 1
},
"filter": "Normal",
"created_time": "1442825564",
"link": "https:\/\/instagram.com\/p\/74vm3GOCEn\/",
"likes": {
"count": 18
},
"images": {
"low_resolution": {
"url": "https:\/\/scontent.cdninstagram.com\/hphotos-xap1\/t51.2885-15\/s320x320\/e15\/11934647_531283580370186_1131008999_n.jpg",
"width": 320,
"height": 320
},
"thumbnail": {
"url": "https:\/\/scontent.cdninstagram.com\/hphotos-xap1\/t51.2885-15\/s150x150\/e15\/11934647_531283580370186_1131008999_n.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "https:\/\/scontent.cdninstagram.com\/hphotos-xap1\/t51.2885-15\/e15\/11934647_531283580370186_1131008999_n.jpg",
"width": 612,
"height": 612
}
},
"users_in_photo": [
],
"caption": {
"created_time": "1442825564",
"text": "#\u0413\u0440\u0430\u043d\u0430\u0434\u0430 #\u0418\u0441\u043f\u0430\u043d\u0438\u044f #photooftheday #picoftheday #instalike #followme #vscogood #vscocam #vsco #instafollow #travel #traveling #instatravel #instalife #tourism #gf #beauty #beautiful #amazing #travelphoto",
"from": {
"username": "solotravel_me",
"profile_picture": "https:\/\/igcdn-photos-h-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/11282631_115839268762391_863189534_a.jpg",
"id": "736938591",
"full_name": "and"
},
"id": "1078821495951073761"
},
"user_has_liked": false,
"id": "1078821489441513767_736938591",
"user": {
"username": "solotravel_me",
"profile_picture": "https:\/\/igcdn-photos-h-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/11282631_115839268762391_863189534_a.jpg",
"id": "736938591",
"full_name": "and"
}
}
...
after that I'm trying use max_id parameter, but I'm not sure which ID I need to use
I tried id of the photo, photo_user id, I even tried timestamp (found this idea on some forum), but every time I receive only first 20 photos
example:
https://api.instagram.com/v1/users/self/media/recent?access_token=TOKEN&max_id=1078821495951073761
I was having the same problem with the empty pagination object while the account actually had more photos.
And just to make things clear here. This question is answered in the comments of the origial question.
There is nothing in the pagination object because the app is in sandbox mode and app's in sandbox mode never returns more than 20 posts(photos).
Use this API for getting all posts of the user:
https://i.instagram.com/api/v1/feed/user/{user_id}
For pagination, the parameter name is max_id
Pass max_id which you have returned in this API's response.
Hope this helps !!

how to get attachments from google+ api activities search?

In https://developers.google.com/+/api/latest/activities#object.attachments, there would have attachments in activities search response, but how to call it?
In here: http://code.google.com/apis/explorer/#_s=plus&_v=v1&_m=activities.search even I select all the fields section, there have no attachments.
The final call url here
https://www.googleapis.com/plus/v1/activities?maxResults=20&orderBy=recent
&query=keyword&fields=id%2Citems(access%2Cactor%2Caddress%2Cannotation%2CcrosspostSource%2Cgeocode%2Cid%2Ckind%2CplaceId%2CplaceName%2Cplaceholder%2Cpublished%2Cradius%2Ctitle%2Cupdated%2Curl%2Cverb)%2Ckind%2CnextLink%2CnextPageToken%2CselfLink%2Ctitle%2Cupdated&pp=1&key=APIKEY
So, how to get attachments?
The attachments will be and a json array nested under the object property.
Here's a sample request:
https://www.googleapis.com/plus/v1/activities?query=google&sortBy=recent&maxResults=20&key=GOOGLE_API_KEY
View it from your browser, and look for "attachments" in the response.
You should see something like this for activities that contain attachments:
"attachments": [
{
"objectType": "article",
"displayName": "Google taking a...",
"content": "insert content..."
},
{
"objectType": "photo",
"image": {
"url": "http://images0-focus-opensocial.g...",
"type": "image/jpeg"
},
"fullImage": {
"url": "http://thenextweb.com/wp-content/...",
"type": "image/jpeg",
"height": 199,
"width": 300
}
}
]
Here's an example of how you can use the activities.search API and extract image attachments:
https://gist.github.com/1296676