Facebook group docs api - php

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);
}
});

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 !');
}
}
);
};

Post photo to facebook page as page

I need to post a photo in a facebook page as page instead of myself.This is my code:
function postFeedBack(userID) {
FB.api('/page_id/photos', 'post', {
access_token : FB.getAuthResponse()['accessToken'],
message: "message",
url : 'image_url',
from : page_id
}, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
I need to post a photo in facebook page as posted by page name, instead of username. Am using the permissions 'publish_stream, manage_pages'.
Thanks,
Please help
Don't forget that the oauth user will need manage_pages permission, too.
Update:
Please see developers.facebook.com/docs/reference/api/page/#photos - also, just to be sure, you are replacing "page_id" with the id of your page, right? Also, double check that the access token is issued to a user who is a Page Manager for said page. In addition, double-check the parameters you're sending. I could be wrong and/or the documentation may be out of date but I do not see "url" as a valid parameter to POST /PAGE_ID/photos. Facebook appears to want image data here in the source parameter. See FB docs link.

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.

Facebook (javascript SDK) create event with image

I'm having a hard time creating a facebook event with a picture.
I've tried many things found on stackoverflow, but most of them are using the php SDK.
Facebook documentation also doen't include an example on how to post a photo to the event.
The code I'm using is:
params = {'name': "some_name",
'picture':"some_img_url_at_my_server",
//or 'picture':"#some_img_url_at_my_server",
//or '#picture':"#some_img_url_at_my_server",
//or 'source':"some_img_url_at_my_server",
//or 'source':"#some_img_url_at_my_server",
//or 'picture':"some_img_path_at_my_server",
//or 'picture':"#some_img_path_at_my_server",
//or '#picture':"#some_img_path_at_my_server",
//or 'source':"some_img_path_at_my_server",
//or 'source':"#some_img_path_at_my_server",
'start_time': "some_date"
};
FB.api('/me/events', 'post', params, function (response) {
if (!response || response.error) {
log(response.error);
} else {
alert('Post ID: ' + response.id);
}
});
The event gets created but no picture is shown.
I read somewhere that I have to url encode the picture data to the post I'm making but I don't know the way to do that in order to try it.
I fetching the data from a php page so, I could do that in the php page as well, but again, I don't know what I have to do exactly.
Can anyone please help?
Thank you
It looks like you have to do this in two steps:
Create the event and get its id.
POST to /EVENT_ID/picture with the picture content in the source parameter.
See here for more details.

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/

Categories