Get Instagram post contents php - php

I want to develop a PHP project for getting the content of an Instagram post (via the post URL). I mean, for example, the crawler getting this Url and returning :
#TBT Used to love carrying them both at once #twinmom #mycoconuts
#mylifeinmyhands #toobignow #istilltrysometimes #LOVE #forevermybabies
After I used the file_get_contents, the of returned response is empty. I don't know how to fix this problem. Can you help me?
I don't want to use the Instagram API!

You shouldn't use this since it will break as soon as Instagram makes a change to their markup, but here you go:
<?php
$instagram_url = "https://www.instagram.com/p/BX6IowXFbq9";
$source = file_get_contents($instagram_url);
preg_match('/<script type="text\/javascript">window\._sharedData =([^;]+);<\/script>/', $source, $matches);
$data = json_decode($matches[1]);
echo $data->entry_data->PostPage[0]->graphql->shortcode_media->edge_media_to_caption->edges[0]->node->text;

This is little late but I am able to fetch Instagram timeline, Specific Media Details.
E.g:
Fetch user's list of post
If Instagram User page url is https://www.instagram.com/marvel then to fetch this page data you can use below URL
https://www.instagram.com/marvel?__a=1
Fetch specific media post details
If Instagram post detail page url is https://www.instagram.com/p/BfeD8RxHwnC/?taken-by=marvel then to fetch this page data you can use below URL
https://www.instagram.com/p/BfeD8RxHwnC/?taken-by=marvel&__a=1

Related

Facebook API, get page post link (PHP)

Here's some code:
$facebookUrl = 'https://graph.facebook.com/'.$facebookPageId.'/posts?&access_token='.$facebookAppId.'|'.$facebookAppSecret;
$facebookData = json_decode(curlRequest($facebookUrl))->data;
curlRequest is successfully returning data but it's limited. The response has the following items:
message
story
created_time
id
It's bad enough these don't include a photo (which all of these posts do) but what's worse is that I have no link that takes me to the post.
Twitter has a redirect using 'https://twitter.com/statuses/'. $post->id; does Facebook have something similar? Or better yet how do I get all of the data for these posts?
Link to the post would be
$facebookUrl = 'https://graph.facebook.com/'.$facebookPageId.'/posts?&access_token='.$facebookAppId.'|'.$facebookAppSecret;
$facebookData = json_decode(curlRequest($facebookUrl))->data;
$link = "http:/fb.com/".$facebookData->id; //This short link will redirect to the pages' post
The $facebookData->id is made up of unique values i.e. the part before "_" (underscore) describes the parent (page,user,group,event) and string after underscore is the post id of its parent.
Adding to Nishant's helpful answer above, Facebook has a lot of other data you can get as part of the Post object, as outlined in their docs. By default, though, all it sends is
message
story
created_time
id
In order to retrieve any other fields, the request has to specify those fields in the query params. For example, if I want the picture and link associated with a Post, I would construct my GET request thus:
https://graph.facebook.com/POST_ID?fields=picture,link&access_token=YOUR_TOKEN
And I would get a response like this:
{
"link": "http://example.com/link",
"picture": "https://example.com/picture",
"id": POST_ID
}
I don't know PHP so can't give the specific syntax for OP's question, but this should get you most of the way there.
Example link for Facebook post:
facebook.com/123123123/posts/890890890/
pattern:
facebook.com/{{page_id}}/posts/{{post_id}}/
where from API post_id => {{page_id}}_{{post_id}}

get title and likeCount youtube API

I used the following code to get title and like count of youtube video:
$gdata_url = 'http://gdata.youtube.com/feeds/api/videos/'.$videoId.'?v=2&alt=jsonc';
$json_content = file_get_contents($gdata_url, 0, null, null);
But currently title of json response always contains https://youtube.com/devicesupport instead of actual title and json response does not contain viewCount.
Could you please advise how to solve the issue?
Youtube API v2 has been deprecated. You can find how to get video info with v3 here.
You use the part parameter to define what properties you want to retrieve. Snippet gives you most of the properties including title and statistics returns the like count. You can use "snippet,statistics" to get both with one call.

How do i get description and title of facebook pages, users in php?

I am using PHP function get_meta_tags to get several info from the different websites like description. When it comes to Facebook it doesn't show any type of description. It gives description for Facebook fan page but not for any users profile page.
$tags = get_meta_tags('https://www.facebook.com/zuck?fref=ts');
echo $tags['og:description'];
I am also facing problems for getting title of Facebook pages as well as users profile page using following script:
$str = file_get_contents('https://www.facebook.com/zuck?fref=ts');
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
return $title[1];
}
Correct title as well as description:
Facebook profile page title as well as description:
You need an Access Token in order to get details of a User profile.
Information about Access Tokens:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
To get Faxcebook page details use below method
http://graph.facebook.com/pageid
or
http://graph.facebook.com/pageusername
Example http://graph.facebook.com/38282497425
The output will be in json format.then use any json decxoding methods .

Displaying a list of videos from a channel - Vimeo Advanced API

I need a way to display videos from a specific channel on a page using PHP.
I have authenticated my app and I can use some methods using the advanced API. I am using the official vimeo PHP library to connect.
Below is what I am trying to do and when I dump the array I do not get anything. I can get info back from using get videos from the entire account method.
require_once('/url/vimeo/vimeo.php');
$vimeo = new phpVimeo('number', 'number');
$vimeo->setToken('number','numbers');
$videos = $vimeo->call('vimeo.channels.getVideos', array('ACCOUNT' => 'NAME'));
If I put the channel name where ACCOUNT is I will get an invalid signature error.
Is it worth using something like simple HTML parser for PHP and doing it that or worth sticking with the advanced API?
I would highly advise using the advanced api. If you parse the html, it will break any time vimeo changes their channel pages. Additionally, channels have more than one layout
eg: vimeohq and nicetype
The second parameter of the "call" function should be any querystring parameters the api method requires.
In the case of "vimeo.channels.getVideos" you can provide
channel_id
user_id
page
per_page
summary_response
full_response.
To experiment with the getVideos method, you can use the playground.
So in the end, I believe you want the function to look like this..
$videos = $vimeo->call('vimeo.channels.getVideos', array('channel_id' => 'NAME'));
where NAME is either the channel id, or the channel name (the channel name matches the url slug, so for example "nicetype" not "nice type"

Instagram: how to get the info of a single picture?

I have a page that shows the latest 50 pics of a certain #hashtag.
I'd like the user to click on the image and go to a page, of the same website, where I can show the full size pic, the title ....
I've searched a lot but I cannot find a way to get the info of a single picture.
Something like this: http://snapwidget.com/view/?id=273145283494542941_10884350#.UE9ukhhwPw8
Thank you!
Have you checked out the Instagram API?
You can use:
https://api.instagram.com/v1/media/MEDIA-ID?access_token=ACCESS-TOKEN
to get the info I've passed the image id in a $_GET variable... Something like this:
http://yoursite.com/image.php?id=3
<?php
//image.php
$image = $_GET['id'];
$info = 'https://api.instagram.com/v1/media/'.$image.'?access_token='.$token;
$response = json_decode($info, true);
//example for full size image
$fullsize = $response['images']['standard_resolution']['url'];
echo '<img src="'.$fullsize.'"/>';
?>
EDIT: also have a look at THIS, it's a PHP wrapper for Instagram, very useful!
I use the shortcode:
From the imgage url, I get the shortcode: eg.: https://instagram.com/p/2rqCzTTdUX/ -> 2rqCzTTdUX
Then, with the following endpoint:
https://api.instagram.com/v1/media/shortcode/{shortcode}?access_token=ACCESS_TOKEN
I get the same data as with the media/{media_id} api. Then, I look for the param 'id' at top level
of data (in the json api's response) -> '985065853803556759_429959980'
Finally, for example, I can use the api get media:
v1/media/{media_id}?access_token=ACCESS_TOKEN

Categories