Requesting multiple Facebook fanpage data in a single call - php

I have about 20 Facebook fanpages setup with a "Welcome/Home" app install across all of them. Is there a way to tally up all the "Likes" from these fanpages to display on my app? I've tried using the JavaScript SDK FB.api() feeding it arrays (using .toString() and .join(',')) as well as JSON objects and even direct input. It seems like Facebook can only handle one fanpage id request for data at a time. I haven't looking yet, but is there a way to do this in PHP. I feel I may run into the same situation.
Suggestions would be great!

Graph URL for Multiple Pages - https://graph.facebook.com/?ids=19292868552,11239244970
Multiple Pages Request as a Facebook JavaScript SDK Example:
FB.api(
'/',
{ids : "19292868552,11239244970"},
function(response) {
if (!response || response.error) {
console.log(response.error);
} else {
console.log(response);
}
}
);
Multiple Pages Request as a Facebook PHP SDK Example:
$result = $facebook->api('/', 'get', array('ids' => array('19292868552','11239244970')));

Related

Tagging friends on Facebook using Graph API

I have developed an app in PHP which
1. process some data on friends of the user (extracted using taggable_friends) and then generates an image and save it on the app server.
2. Shows the image to the user and offers option to share the image on their timeline.
3. Now I need to tag some friends also in that timeline post [as I should use taggable_friends for tagging also not just for getting friends of the user as per Fb guidelines].
I'm using this code to get list of friends
$friends = $fb->get('/me/taggable_friends?fields=name,first_name,id,picture.width(80).height(80)&limit=500')->getGraphEdge()->asArray();
But I don't know how to tag the friends [using PHP] on the timeline while sharing using Javascript. Please help. I can't find an answer to do this job which still works in 2016.
Javascript code to share
function shareOnFacebook() {
var response = '';
FB.ui(
{
method: 'share',
href: linkToShare,
},
function(response) {
if (response && response.post_id) { } else {
alert('Something went wrong !');
}
}
);
};

How to pass facebook login response from javascript to php page?

I am trying to add loing with facebook feature to my website, I used javascript to connect to facebook API, As you know facebook sends object named "response", I want to pass this object to my index.php page to read its content their.
could you please tell me how to pass and read this opject
If you need to work with facebook from your server, you can't use just js auth.
You need to implement "server login", described at Login for Server-side Apps
You need not implement all that complicated things, just find any library from internet, FB have its own library for php as I know, and use it to make server login. You can find many examples how to do it.
You can done with it by using jQuery.ajax() or jQuery.post() function. but it is not secured. Because js is open for all browser. Bad guys can send unexpected data and take chances to harm your app / web. Anyway it is your choice.
You can add a function here i have used replace_login() in FB.getLoginStatus() as following:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// connected
replace_login();
} else if (response.status === 'not_authorized') {
// not_authorized
} else {
// not_logged_in
}
});
Now write replace_login() in same file and after FB.getLoginStatus() as below:
function replace_login(){
FB.api('/me', function(response) {
$.post("http://yourdomain.com/ajax_post_login",{ username: response.username, name: response.name, fb_res: response }, function(data) {
alert(data);
})
});
}
Check facebook server-side-login, it will help you more.

Save facebook webpage after user authorization using PHP or Javascript

After I login facebook I want to save the content of https://www.facebook.com/pages (no specific page id but the url as you see it, and see suggested Favorite Pages, not pages I like or selected)
I am not trying to obtain the list of the pages the user admins, nor the list of pages they like. So /me/accounts or /me/likes are not useful. I try to obtain all the pages that are added in Facebook, from the last time I visited this url and it suggests them as pages I may like
I am using the example of http://developers.facebook.com/docs/reference/php/ and I take the profile of user I have. So far so good.
I tried to retrieve data using
$facebook->api('/me/pages'),
$facebook->api('/pages'),
$facebook->api('/pages'),
$facebook->api('/id=USER_ID/pages')
and so on but all of them where wrong or by using Graph API pages?id=USER_ID there were Unsupported get/post request.
As Igy said "Suggested pages is not a feature of the API, only the facebook.com interface"
Something else I tried is to save the url with file_get_contents. As urls I used the
ini_set('user_agent','MSIE 4\.0b2;'); //to pretend that I am a browser, it works
http://www.facebook.com/pages?id=USER_ID and
http://www.facebook.com/pages
Although the save is done properly, facebook doesn't recognize the authorization and shows the page I want but for users without login.
I tried javascript in Facebook JavaScript Test Console and after logging in it opens the page recognizing authorization. The code is
<div id="authResponse"></div>
<script>
var
div = document.getElementById('authResponse'),
showAuthRecord = function(response) {
if (!response.authResponse) {
div.innerHTML = '<em>Not Connected</em>';
} else {
var html = '<table>';
for (var key in response.authResponse) {
html += (
'<tr>' +
'<th>' + key + '</th>' +
'<td>' + response.authResponse[key] + '</td>' +
'</tr>'
);
}
div.innerHTML = html;
}
};
FB.getLoginStatus(function(response) {
showAuthRecord(response);
FB.Event.subscribe('auth.authResponseChange', showAuthRecord);
});
window.open('https://www.facebook.com/pages','mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
</script>
Is there a way to do this in PHP, or Graph API or FQL Query ? Or add in javascript, code to save the page I open ? I haven't found anything yet.
What you are asking for is not possible to obtain through the Facebook Platform. And trying to scrape a page to extract information from is also against Facebook terms:
You will not collect users' content or information, or otherwise
access Facebook, using automated means (such as harvesting bots,
robots, spiders, or scrapers) without our prior permission.
Also you cannot ask the users for their password and login information, please refer to the Facebook Platform Policies:
You must not include functionality that proxies, requests or collects
Facebook usernames or passwords.

Tracking successful Facebook Shares

I have a website built in Drupal and I have both the fbconnect module and the facebookshare module. I want to figure out the easiest way to confirm that a user in fact shared the piece of content. I've seen a couple threads but I still seem unable to figure it out. Can anyone lend a hand? I've been at this for a few days.
If you include the Facebook Javascript SDK in your pages, then you can initiate facebook's share dialog and be able to recieve a callback once the dialog closes.
Here is an example taken from the FB.ui() documentation :
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
As you can see, the callback's argument (response) includes an attribute called post_id - this is the post_id of the story that was created when the user shared the content. As long as the user does not manually (or some other way) delete that story, you will be able to retrieve information about that post (comments,likes,etc..) based on that post_id at anytime.
You can use the Insights of your application to get statistical information on content shares. Please review: https://developers.facebook.com/docs/reference/fql/insights/
I ended up finding a simple solution, there's a link you can repurpose with an app ID and some URL params, one of the params happens to be a return url so I can process accordingly, with a little $_SESSION I can connect the share's success to the user.
https://developers.facebook.com/docs/reference/dialogs/feed/

Facebook group docs api

Is it possible that i can post and retrieve a group's documents with the facebook group api? i have went through the documentation and couldn't find anything that explain how this can be achieved, if anyone know where i can get this please give the link url so that i can go and read it myself. In short i want to retrieve and be able to post documents to a facebook group through a facebook api, either javascript or PHP. basically i'm just looking for a place where i can go and read for myself how this can be done not to be fed with code but if there is any code working out there then don't hesitate to post it.
Thanks
Donald
The only page in the Facebook API docs I found that mentions group documents is this:
https://developers.facebook.com/docs/reference/api/group/
You can retrieve the documents of a group with the docs connection of the group.
Use a URL of this form:
https://graph.facebook.com/group_id/docs?access_token=...
With the ID of a doc, you can request it directly:
https://graph.facebook.com/doc_id?access_token=...
Using the JavaScript SDK:
FB.api('/doc_id', function(doc) {
alert(document.body.innerHTML = doc.message);
});
Posting a doc
(requires permissions publish_stream and manage_groups)
var doc = {
subject: 'Test',
message: 'This is a test doc.'
};
FB.api(group_id + '/docs', 'post', doc, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Doc ID: ' + response.id);
}
});

Categories