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.
Related
I'm having trouble using the API to view a segment. I'm using PHP. My code is as follows:
$url = "https://us7.api.mailchimp.com/export/1.0/list/?apikey=$api_key&id=$list_id&$segment";
$result = file_get_contents($url);
where $segment is an array used to generate the segment.
I can get the following version working...
$segment = "segment[match]=all"
"&segment[conditions][0][field]=LNAME".
"&segment[conditions][0][op]=like".
"&segment[conditions][0][value]=smith";
which generates a segment of all subscribers to my list with a last name containing "smith".
However, what I actually want to do is generate a segment based on people who've been sent any mailer in the last 7 days. I've created this manually to get the correct fields and generated the following array based on it:
$segment = "segment[match]=all".
"&segment[conditions][0][condition_type]=Aim".
"&segment[conditions][0][field]=aim".
"&segment[conditions][0][op]=sent".
"&segment[conditions][0][value]=last7day";
but it's giving me a 300 error. This isn't listed in MailChimp's current error glossary on the export api documentation, but according to a snapshot of the old error documentation means "Campaign doesn't exist" (https://web.archive.org/web/20130209144951/https://apidocs.mailchimp.com/api/1.3/exceptions.field.php) which is weird because I'm not referencing a campaign.
What am I doing wrong?
// , Click on playground and with your API key.
Generate some responses and look at the campaign id.
It's not the integer value you see when hovering over the campaign with id=, it's another value.
Look for the id that the API needs in the response.
This will fix your issue.
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
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}}
I want to use facebook php api to post a comment,
but I only know the page url, no post id,
how to know the post id base on url given?
$post_data=array(
'message'=>'post a comment test',
'link'=>'http://www.persunmall.com/p19000', // how to know post id
);
// how can i know the post id base on the link?
$facebook->api('/'.$post_id.'/comments','post',$post);
The post ID can be found in the array returned from the call to $facebook->api.
For example:
$facebook->api(<your API call>);
Then you can find the post ID in $result['id'] when making a call to 'feed', as demonstrated here
$result = $facebook->api('/121468571287906/feed/','post',$attachment);
Additionally, Facebook's API returns a response object, which will contain a post ID for the original call. Try adding a return value to your original call, and then examining that. For example, examine the details of $returnObject for this code:
$returnObject = $facebook->api('/'.$post_id.'/comments','post',$post);
Please refer to the Facebook API reference for details.
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"