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}}
Related
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
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"
I've recently started developing a portfolio website which I would like to link to my wordpress blog using simplepie. It's been quite a smooth process so far - loading names and descriptions of posts, and linking them to the full post was quite easy. However, I would like the option to render the posts in my own website as well. Getting the full content of a given post is simple, but what I would like to do is provide a list of recent posts which link to a php page on my portfolio website that takes a GET variable of some sort to identify the post, so that I can render the full content there.
That's where I've run into problems - there doesn't seem to be any way to look up a post according to a specific id or name or similar. Is there any way I can pull some unique identifier from a post object on one page, then pass the identifier to another page and look up the specific post there? If that's impossible, is there any way for me to simply pass the entire post object, or temporarily store it somewhere so it can be used by the other page?
Thank you for your time.
I stumbled across your question looking for something else about simplepie. But I do work with an identifier while using simplepie. So this seems to be the answer to your question:
My getFeedPosts-function in PHP looks like this:
public function getFeedPosts($numberPosts = null) {
$feed = new SimplePie(); // default options
$feed->set_feed_url('http://yourname.blogspot.com'); // Set the feed
$feed->enable_cache(true); /* Enable caching */
$feed->set_cache_duration(1800); /* seconds to cache the feed */
$feed->init(); // Run SimplePie.
$feed->handle_content_type();
$allFeeds = array();
$number = $numberPosts>0 ? $numberPosts : 0;
foreach ($feed->get_items(0, $number) as $item) {
$singleFeed = array(
'author'=>$item->get_author(),
'categories'=>$item->get_categories(),
'copyright'=>$item->get_copyright(),
'content'=>$item->get_content(),
'date'=>$item->get_date("d.m.Y H:i"),
'description'=>$item->get_description(),
'id'=>$item->get_id(),
'latitude'=>$item->get_latitude(),
'longitude'=>$item->get_longitude(),
'permalink'=>$item->get_permalink(),
'title'=>$item->get_title()
);
array_push($allFeeds, $singleFeed);
}
$feed = null;
return json_encode($allFeeds);
}
As you can see, I build a associative array and return it as JSON what makes it really easy using jQuery and ajax (in my case) on the client side.
The 'id' is a unique identifier of every post in my blog. So this is the key to identify the same post also in another function/on another page. You just have to iterate the posts and compare this id. As far as I can see, there is no get_item($ID)-function. There is an get_item($key)-function but it is also just taking out a specific post from the list of all posts by the array-position (which is nearly the same way I suggest).
I just saw it is working for others. I dont know whether it is working to everyone, or just working to few people.
My coding is not suddenly working for the last two days.
It is PHP graph api
$facebook->api('/me/photos?access_token='.$access_token, 'post', $arguments);
This is how it is uploaded.
Nothing was changed. It was working fine. It is all not working for the last two days.
Error is
OAuthException: (#100) Cannot specify user tags without a place tag
$arguments is an array which contains the image, tags (which is also an array) and message
I have the same problem! The same code, but don't work for the past 24 hours.
I use graph api via Action Script. I HTTP POST a request with a parameter Object, which contains tag_uid, x, and y. Bad request just as following:
{
"error": {
"message": "(#100) Cannot specify user tags without a place tag",
"type": "OAuthException",
"code": 100
}
}
The API didn't recognize the x parameter and y parameters. So, I tried to use the api method /photoID/tags. This way works without specifying the x and y parameters, if you do specify them, it won't work.
https://developers.facebook.com/docs/reference/api/user/#posts
tags
Comma-separated list of Facebook IDs of people tagged in this Post. For example: 1207059,701732. This field is returned as the
with_tags field when the Post is read.
NOTE: You cannot specify this field without also specifying a place.
So I think you should also specify the place (page Id of the location associated with the post) in order to put tags.
You have to add place value to the params. place value is page_id in facebook.
sample actionscript code is as following
tagArr = '[{"tag_uid":"' + String(userVO.uid) + '", "x":"1", "y":"1"}]';
var params:Object = {access_token:userVO.accessToken, place:"123456789", tags:tagArr, image:bitmap, message:msg, fileName:'FILE_NAME'};
Facebook.api('/'+userVO.uid+'/photos', onCompleteHandler, params);