Facebook PHP SDK event wall posts limit and pagination - php

Hi I created an app to load facebook event "wall posts" and "attending list" into a searchable form for use by door staff as a guestlist.
Recently it won't pull more than 10 posts from an events wall posts.
I've been playing about on the open graph explorer and have ran into the same problem. I can't get it to display more than ten results.
Why does it paginate now and why even if I add "since" and "until" parameters to the call does it still only display the last 10 posts on the wall?
If anyone could help me remove the pagination and get all results at once that would be magical!
Here's my call in my php:
$event_id = intval($_GET['id']);
$comments_id = '/' . $event_id . '/feed?fields=id,from,message';
$guestlist = (new FacebookRequest( $session, 'GET', $comments_id ))->execute()->getGraphObject()->getPropertyAsArray('data');
$i = 0; while($guestlist[$i]) {
echo $guestlist[$i]->getProperty('from')->getProperty('name');
echo nl2br($guestlist[$i]->getProperty('message'));
$i++;
}
Here's an example of an open graph request:
941122979255816/feed?fields=id,from,message
Here's an example facebook event:
facebook.com/events/941122979255816/
Here's my app:
events.sawhost.co.uk
Thanks

It seems that facebook is having some pagination issues. I guess all we can do is sit tight while they fix it
https://developers.facebook.com/bugs/809829259052996/

Related

Facebook API (PHP) : Get Full Ads List

I am using Facebook API to fetch the full Ads list.
The Code is working, But it return only 25 Ad in case of i have 150+ Ad in my account.
I guess that happens because of the query limits on the Facebook API.
My Code:
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->read();
$fields_adset = array(
AdSetFields::ID,
AdSetFields::NAME,
AdSetFields::CAMPAIGN_ID,
AdSetFields::STATUS,
);
$ads = $account->getAds($fields_adset);
foreach ($ads as $adset) {
$adset_id = $adset->{AdSetFields::ID};
echo $adset_id;
//print_r($adset);
//exit();
}
So, they mentioned in the documentation that :
Use Asynchronous Requests to query a huge amount of data
Reference (1) : https://developers.facebook.com/docs/marketing-api/best-practices/
Reference (2) : https://developers.facebook.com/docs/marketing-api/insights/best-practices/#asynchronous
But, I can't apply that "Asynchronous" requests to my code to fetch the Full Ad List,
Please help me to fetch the full Ads list
Thank you.
You should implement pagination (or request a limit more high). With the PHP SDK you can implement the cursor as described in the doc here or more simply set the Implicit Fetching, as example:
..
use FacebookAds\Cursor;
...
Cursor::setDefaultUseImplicitFetch(true);
$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->read();
$fields_adset = array(
AdSetFields::ID,
AdSetFields::NAME,
AdSetFields::CAMPAIGN_ID,
AdSetFields::STATUS,
);
$ads = $account->getAds($fields_adset);
foreach ($ads as $adset) {
$adset_id = $adset->{AdSetFields::ID};
echo $adset_id;
//print_r($adset);
//exit();
}
Hope this help

Delete Outlook 365 Calendar Event Through API

I am trying to delete a calendar event through the REST API and it is returning a 400 error.
The DELETE url:
https://outlook.office.com/api/v2.0/events/AQMkADA...URF1shGWDYAAAIBDQAAAOVip_uuQf5ApURF1shGWDYAAAAwSb9FAAAA
The call is generated in PHP using this code sample.
$delete_url = $outlookApiUrl . $outlook_id;
$response = $this->makeApiCall($this->access_token, $this->email, 'DELETE', $delete_url);
The URL was missing a "Me"
https://outlook.office.com/api/v2.0/Me/events/AQMkADA...

Display Facebook ADs Statistics on webpage using Facebook Ads API in PHP

Does anyone know how to fetch all facebook ads statistics and display on webpage using Facebook Ads Api-PHP SDK. I am using this API and I am getting campaign details like name of campaign, id, status. but not able to get impressions,clicks, spent.
What I am doing let me share with you:
1) I am getting access token by authorizing user
2) After getting access token, I am using below code
$account = new AdAccount('act_XXXXXXXXXXXXXXX');
$account->read();
$fields = array(
AdCampaignFields::ID,
AdCampaignFields::NAME,
AdCampaignFields::OBJECTIVE,
);
$params = array(AdCampaignFields::STATUS => array(AdCampaign::STATUS_ACTIVE,AdCampaign::STATUS_PAUSED,),);
$campaigns = $account->getAdCampaigns($fields, $params);
/* Added By Jigar */
$campaign = new AdCampaign('XXXXXXXXXXXXXXXX');
$compainDetails = $campaign->read($fields);
3) then printing the array
echo "<pre>";
print_r($compainDetails);
exit;
If anyone know any suggestion in above code, please share. All code is in PHP. Dose anyone have any tutorial that fetch all above required data then share it
You could try to use the facebook insights api instead of $campaign->read. Here's an example:
https://developers.facebook.com/docs/marketing-api/insights/v2.5#create-async-jobs
What you have to do to get impressions, click and spent is to add these fields to the $fields param. In your case, the complete code should look like the following:
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Values\InsightsLevels;
use FacebookAds\Object\Values\InsightsFields;
$campaign = new Campaign();
$fields = array(
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::CALL_TO_ACTION_CLICKS,
InsightsFields::INLINE_LINK_CLICKS,
InsightsFields::SOCIAL_CLICKS,
InsightsFields::UNIQUE_SOCIAL_CLICKS,
InsightsFields::SPEND,
);
$params = array(
'level' => InsightsLevels::CAMPAIGN,
);
$async_job = $campaign->getInsightsAsync($fields, $params);
$async_job->read();
I don't know what exactly the "click" param means for you, but if you take a look at all these click params, I'm sure you'll find it or you'll know how to calculate it.
For a complete list of fields available on insights objects, have a look at: https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Object/Fields/InsightsFields.php
Hope that helps.
Regards, Benjamin

How to tag user(s) in comment via facebook php sdk?

I'm trying to tag user(s) inside page post comments.
$fb_id = 'facebook_user_id_here';
$fb_name = 'facebook_user_name_and_surname_here';
$request = new FacebookRequest(
$this->session,
'POST',
$comment,
array(
'access_token' => $this->page_access_token, //it is access token of my page
'message => "Text here #[".$fb_id.":1:".$fb_name."]"
)
);
It shows only name and surname without Fb profile URL.
Like CBroe mentions in his comment, at this time this is not possible using the API.
For reference, this is called "mentioning" or "mention tagging", and personal profiles can only do this in messages on open graph actions (docs).
Pages can also mention other pages in comments. (docs)

facebook october 2013 migration affects likes.count field in Graph Api call

When i enable migration to october 2013, likes.count field is not seen for each post of fb page/group by Graph Api feed call.So this field per post will be permanently removed from Graph api call like pageid/feed?limit=20 on october.
But i show this feed in many websites with how many total likes per post.so then i have to find alternatives,so is i got through google.com that -
It's needed to have another Graph api or fql query call for likes count per post along with the first call for page feed
so if it's possible to know likes count per post in only one Graph Api call, then tell me or what is the correct way to go for another Graph Api,Fql query call for all likes count per post?
Once you have loaded the Facebook page feed:
$config = array();
$config['appId'] = your_app_id;
$config['secret'] = your_secret_number;
$confif['fileUpload'] = false;
$facebook = new Facebook($config);
$pageid = facebook_page_id;
$pagefeed = $facebook->api('/' . $pageid . '/feed');
You can loop through the data and find a field called 'likes'.
With an other loop you can get the total number of likes for the corresponding post.
If you want the number of likes for a posted comment there is also a field called 'like_count'
that directly gives the number of likes for this comment.
Retrieving likes count per post :
foreach ($pagefeed['data'] as $post)
{
$likes_number = 0;
if (isset($post['likes']))
{
foreach ($post['likes']['data'] as $like)
$likes_number++;
}
}
Retrieving likes count for each comment :
if (isset($post['comments']))
{
foreach ($post['comments']['data'] as $comment)
{
echo $comment['like_count'];
}
}

Categories