Read new Facebook Pixel Stats - php

I need to create an admin panel of sorts for a client that will present him with data of conversion values over specific time intervals, for his eshop which has the New Facebook pixel installed.
Assume I've properly configured the Standard Event I want to track. The part where I'm stuck is actually reading the data via the Facebook Marketing php sdk. It is supposed to look something like that:
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/{ads-pixel-id}/stats'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
Am I looking at the right place? Can I still get these kind of stats or is this behavior deprecated? The Facebook documentation isn't very clear on this and everywhere I look I see deprecated pages and code,

You need to add an aggregation like this:
/{ads-pixel-id}/stats?aggregation=event

Related

Facebook API obtain photos

I am looking for a fairly simple way of obtaining pictures from Facebook. I have a client that has pictures that he uploads to Facebook quite often. He wants a way for those pictures to be populated on the website that I built for him a while ago. I thought doing it with google drive would be a fairly easy solution for him, but it has not been.
I am trying to create a simple page that grabs his folders that the images live in with the graph api, without having to do a lot or having users logged in. What is going to be the easiest way of doing this?
I tried the explorer for the api and have the following code.
<?php
$request = new FacebookRequest(
$session,
'GET graph.facebook.com',
'/me',
array(
'fields' => 'id,name,photos{album}'
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
?>
I for now would just like to be able to echo the elements so that I can learn how it works, after that I can refine it. What am I doing wrong?

Get news feed using Facebook Graph API

I am using the following to make my requests to Facebook
$facebook->api('/feed',
array(
'access_token' => $_SESSION['fb_access_token'],
));
However, I want to get the news feed of the user.
Not to be confused: I do not want the feed of a certain user, much less of a given page.
I want the News Feed/Feed Stream the user views when accessing Facebook, one that contains the posts of your friends, etc.
How is this possible?
Make an API call to /me/home or /user_id/home where user_id is the current session user.
You are also using the old PHP SDK
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/home'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
Reference: https://developers.facebook.com/docs/graph-api/reference/v2.2/user/home
UPDATE:
The latest Graph API doc suggests the following:
As of October 6th, 2015, this endpoint is no longer available. Please consider using the /user-id/feed edge instead.
This effectively means we cannot access the user news feed provided by Facebook but will have to rely on /user-id/feed as an alternative.
The endpoint is me/home.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/home
The posts that a person sees in their Facebook News Feed.
Getting all recent notifications including read via Graph API, call:
graph.facebook.com/USER_ID/notifications?include_read=true

I can't Access facebook Pages(account) details php sdk 4.0

I want get my facebook page details. I am using php sdk 4.0 and facebook documentation gives
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/accounts'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
but After running this code
My output is
Facebook\GraphObject Object ( [backingData:protected] => Array ( ) )
so If i miss anything in my code Or any other things
Thanks
If you use a test app (the main app was not submitted for fb review) you should use the test account to make request. On real account will give you an empty object/array.
More info
https://developers.facebook.com/docs/apps
Read about test apps and test users.
I got the solution using facebook extended profile management
http://developers.facebook.com/docs/authentication/permissions
You can do this if you are using Facebook, connect by passing scope=email in the get string of your call then to the Auth Dialog.
It is in the Facebook doccumentation

Getting list of events from a Facebook Page

So I have a friend who is a musician and has a page set up. He has asked me if there is a way of getting all the events on his Facebook Page via the Graph API and then putting them onto his website. I said I'd look into if this is even possible given that the API is now at version 2 and the PHP SDK has been bumped up to version 4.
Does anyone know how I'd do this? I already know how to make 'GET' request using the new PHP SDK, however I don't seem to be able to get the necessary fields.
Any help would be great!
Thanks!
It's given on developers.facebook.com
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/{page-id}/events'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
More at https://developers.facebook.com/docs/graph-api/reference/v2.0/page/events
Hope this Helps.

Get wall feed from a public Facebook page using Graph API - is it really this complex?

I have started off by reading Displaying Facebook posts to non-Facebook users which is of some use but I cannot believe it is this difficult to get a public feed from Facebook.
The page I want a feed from is public, you do not need to be logged into get to it.
Am I right in presuming that I need an access_token to get to this information, attempting to access the URL without results in an OAuth error.
So the flow should be like this (massively, overly complex):
Authenticate using a user (what if the user isn't on Facebook?)
Some complex OAuth nonsense - just to read the feed, I do not even want a like button or post to wall functionality
Get the feed using a PHP request to the correct URL with the user's access_token
Render the feed
Assuming the user isn't on Facebook, what do you do, use a generic app to get the feed?
Hardcode an auth request to Facebook using my generic app's ID and secret
Some complex OAuth nonsense
Get the feed using a PHP request to the correct URL with the app's access_token
Render the feed
Oh no, the auth has expired, re-auth and capture this new access_token for use in future requests.
This seems really complex for no reason other than Facebook wants to know EVERYTHING that is going on, it'd be easier to do a cURL and scrape the content from the public URL using XPath.
Any help on this would be great.
Thanks,
Jake
EDIT
An edit to show this is not an exact duplicate.
I had this working with an access_token in place, but now it fails, the token has expired and I can no longer use it to obtain information from the public wall.
I attempted to extend the expiration date of this token using the methods mentioned in other posts but this didn't work and the expiration was not extended - we are now here, with an invalid token and no further along.
It seems that the manual process of having to approve the OAuth request means that it is impossible to programatically get the feed of a public page.
Two years later, you can programmatically do this with a Facebook App (an example using PHP and Slim): https://developers.facebook.com/apps/
$base_api="https://graph.facebook.com/";
$client_id="XXXXXX";
$app_secret="XXXXXX";
//get a profile feed (can be from a page, user, event, group)
$app->get('/feed/:profileid/since/:start_date', function ($profile_id,$start_date) {
$start_time=date('m/d/Y h:i:s',$start_date);
$request = new FacebookRequest(
getSession(),
'GET',
'/'.$profile_id.'/feed?since='.$start_time
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
//do something with $graphObject
});
function getSession(){
$session = new FacebookSession(getAccessToken());
return $session;
}
function getAccessToken(){
global $base_api, $client_id, $app_secret;
$url=$base_api."oauth/access_token?client_id=".$client_id."&client_secret=".$app_secret."&grant_type=client_credentials";
$str = file_get_contents($url);
$token = str_replace ( "access_token=" , "" , $str );
return $token;
}
I have some success with reading in the direct feed without tokens etc.
(using magpie, simplepie or querypath or similar).
http://www.facebook.com/feeds/page.php?format=rss20&id=........
http://www.facebook.com/feeds/page.php?format=atom10&id=........
found on: http://ahrengot.com/tutorials/facebook-rss-feed/
Facebook has changed how to retrieve a public Facebook page's feed since the other answers were posted.
Check out my answer/question. It's not PHP, but it provides the URLs and process you need.

Categories