how to get user id on facebook request dialog - facebook

What i want to do is get the request ID and insert to my database. My request dialog is run well, but the problem is I cannot get 'TO' user id http://developers.facebook.com/docs/reference/dialogs/requests/ , but I still cannot get the request user ID.
here is my coding:
function newInvite(){
//var user_ids = document.getElementsByName("user_ids")[0].value;
FB.ui({
method : 'apprequests',
title: 'X-MATCH',
message: 'Come join US now, having fun here',
},
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
);
}
any solution on this?
million thanks for help

Have you enable request 2.0 efficient?
If you have enabled, you can get the user id easily as the response like this
{
request: ‘request_id’
to:[array of user_ids]
}
In your callback function, you can use
response.request to get the request ID
response.to to get the array of user ids
And notice that if you use request 2.0, the request ID format will like this
<request_object_id>_<user_id>
If you doesn't enable it, then you can only get the array of request ids and you need to make another api call to get the user id
Edited:
FB.ui({
method : "apprequests",
title : "your title",
message : "your msg"
},
function(response) {
var receiverIDs;
if (response.request) {
var receiverIDs = response.to; // receiverIDs is an array holding all user ids
}
}
);
Then you can use the array "receiverIDs" for further process
For example I sent a request to user id with id "1234", "5678"
The response will like this:
{
request: ‘1234567890’ // example,
to:['1234', '5678']
}
In request 2.0, the full request id will look like this
1234567890_1234
1234567890_5678
Caution: FB doc tell you to manage and delete the request yourself, if you using request 2.0,
remember to delete the id like the above, if you directly delete the request '123456789', all the full request ID with this prefix will be deleted.
==================================================================
If you haven't enable request 2.0, follow the code on the doc page to see how to get the user id by making a api call
function getMultipleRequests(requestIds) {
FB.api('', {"ids": requestIds }, function(response) {
console.log(response);
});
}
The response format for these methods is as follows:
{
"id": "[request_id]",
"application": {
"name": "[Application Name]",
"id": "[Application ID]"
},
"to": {
"name": "[Recipient User Name]",
"id": "[Recipient User ID]"
},
"from": {
"name": "[Sender User ID]",
"id": "[Sender User Name]"
},
"message": "[Request Message]",
"created_time": "2011-09-12T23:08:47+0000"
}
you can implement the callback of api call and getting who is the receiver by response.to.id

Related

How to include images in page post API

I keep getting this error message when am attaching images to page post
message: '(#10) Application does not have permission for this action'
but when am posting message only, it works fine
FB.api('PAGE_ID/feed', 'post', {
message: 'Message is here',
link: 'https://my_LINK.com',
"child_attachments": [
{
"link": "https://1.jpg",
"image_hash": "hash1",
"name": "Some Name",
"description": "Some description"
},
{
"link": "https://2.jpg",
"image_hash": "hash2",
"name": "Some Name",
"description": "Some description 2"
}]
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
});
to add multi images to a post in facebook, it has to be done in 2 steps as per facebook
to upload image, refer to this and to make the post
function post_fb_ad(description, ad_images) {
attached_media = []
for (var adImg of ad_images) {
attached_media.push({ media_fbid: adImg.id })
}
FB.api('page_id/feed', 'post', {
message: description,
attached_media: attached_media,
access_token: EXD_ACCESS_TOKEN
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log('post id is ', res)
});
}
In order to publish to a page, you will need to use a page access token that has publish_pages permission which you may be missing.
You can quickly test the request using the Graph API Explorer tool.
You can also use the Access Token Debugger tool to test what permissions your access token has.
Also, note that publish_pages permission is reviewable and needs to be approved before you can use it with the general public. Prior to approval, you can only test it with an app where you are an admin and in a page where you have admin role.

Ionic app with option to attend facebook events

I'm doing a hybrid app using Ionic framework.
I want to implement a facebook event system to attend some events. I have this:
ngFB.api(
'/666945880120392/attending',
'GET',
{},
function(response) {
// Insert your code here
}
);
and I have ngFB in my app.js file like this:
ngFB.init({appId: '[APP_ID]'});
The error I have is:
openfb.js:256 GET https://graph.facebook.comundefined/?access_token=undefined net::ERR_NAME_NOT_RESOLVED
I was looking for a solution but no answer. I also try in the developer facebook console and the answer is correct:
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=666945880120392%2Fattending&version=v2.7
What it's happening? Thanks!
EDIT 1
Thanks to #e666 I did now this
ngFB.api({
method: 'GET',
path: '/666945880120392/attending'
}).then(function(response) {
console.log(response);
}).catch(function(error) {
console.error(error);
});
And the error now is that if I'm logged with an account always the return in the event is:
Object {data: Array[1], paging: Object}
And inside data is the name of another person, the unique person that is attending to the event and no the person who is logged with the access token.
Thanks!
EDIT 2
I opened another question because this is not the result than I hope, I need to go to an event, no to get the list of the people that goes to the event.
I have this now:
ngFB.api(
"/666945880120392/attending",
function (response) {
if (response && !response.error) {
console.dir(response);
}
}
);
the access_token is ok, and the response is
openfb.js:256 GET https://graph.facebook.comundefined/?access_token=EAABlK6y7pOUBAN3CPWdZB5FL…LCpXL9Bd3ELHQZAA6EJc6cCheAxUUnL59ZCZAf7aROCapJxiu991fxjDkxmMO651rfuREwZDZD net::ERR_NAME_NOT_RESOLVED
In the page of facebook https://developers.facebook.com/tools/explorer/?method=POST&path=666945880120392%2Fattending&version=v2.5
The response is
{
"error": {
"message": "(#299) Requires extended permission: rsvp_event",
"type": "OAuthException",
"code": 299,
"fbtrace_id": "G7HFJ48pbkx"
}
}
But I have this permission. Can someone help me please?
First, the path is undefined because you don't use correctly the method api. That is how you need to use it :
ngFB.api({
method: 'GET',
path: '/666945880120392/attending'
}).then(function(response) {
console.log(response);
}).catch(function(error) {
console.error(error);
});
Furthermore, you have undefined in access_token. As I looked in the library code, I am not sure that you can use this library without login as a user to have an access_token.
To have an access_token you need to use this function :
ngFB.login({scope: 'email'}).then(function(response) {
console.log('Access token' + response.authResponse.accessToken);
}).catch(function(error) {
console.error(error);
});
The access_token will then be automatically attached to request that you make with OpenFB.
You can find more complete examples of how to use the library is the github here : https://github.com/ccoenraets/OpenFB/blob/master/indexng.html

Facebook Mutual Friends API

Using the Facebook Graph API (v2.4), I can't seem to access any information about mutual friends, not even the total count.
Here's my graph query (User ID changed for privacy purposes):
https://graph.facebook.com/v2.4/123456789?fields=context.fields(mutual_friends)
The result I get is:
{
"context": {
"id": "dXNlcl9jb250ZAXh0OgGQBqWf9ZAHMZA1yjZBJZABsMDkDORNsle8wkS8Acci9r4FsOdyRVl1TSGSXAsofmlaWYS05piSZCV9F1QwNNs0L9XpNuGLAaLyMk8Fnaiwyxpm5shUZD"
},
"id": "123456789"
}
I tried using FB's iOS SDK to make the same query as well, but got the same result.
Any suggestions?
The all_mutual_friends, mutual_friends, and three_degree_mutual_friends context edges of the Social Context API were deprecated on April 4, 2018 and immediately started returning empty data sets. They have now been fully removed.
The {user_id} must be another user of your app, and the user access token you MUST use is from another user of your app.
Then
GET /{user_id}?fields=context{mutual_friends}&access_token={other_users_access_token}
should work and give results, if both users gave your app the user_friends permission.
See
https://developers.facebook.com/docs/graph-api/reference/user-context#Reading
https://developers.facebook.com/docs/graph-api/reference/user-context/mutual_friends/
function aa_mutl_frnd(x, row)
{
FB.init({
appId : '<?php echo get_option('_fb_apps_id');?>', //Facebook apps id using theme option
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.5' // use graph api version 2.5
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
console.log(':acc_tk:'+accessToken);
//////////////////////////////////////////////////////////
var data={
'action': 'wq_accss_tkn_gnrt',
'ddt' : accessToken
}
$.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function (response) {
console.log(':acc_tk2:'+response);
FB.api(
"/"+x+"",
{
"fields": "context.fields(all_mutual_friends)",
//"access_token": '',
"appsecret_proof": response,
},
function (response) {
console.log(response);
}
);
});
////////////////////////////////////
}
});
}
/// ajax part /////
add_action('wp_ajax_wq_accss_tkn_gnrt', 'wq_accss_tkn_gnrt');
add_action('wp_ajax_nopriv_wq_accss_tkn_gnrt', 'wq_accss_tkn_gnrt');
function wq_accss_tkn_gnrt() {
echo hash_hmac('sha256',$_POST['ddt'],'app_secret');;
die();
}

Facebook custom share alternative to feed dialog

Hi i'm working on a test site to share personalized content non linked to og.
I'm at the point that i have implement the FB.ui method feed but i read that it's deprecated.
So i have looked for the new share_open_graph with object and action.
Now i can create an action and share it, but when i share it don't appear in the board but only in the timeline. and as i read on the rules this function make 2 call that can be passible to ban/suspension.
the site is:
www.paris-web.it/test.html
you can see all the code directy in page/with inspector
function postLike(){
accessToken = FB.getAuthResponse().accessToken;
FB.api(
'me/objects/article',
'post',
{
object: {
"app_id": fbAppId,
"type": "article",
"url": objectToLike,
"title": "my title",
"image": logoImage,
"description": "my desc",
"expiration_time": "2014-07-23"
}
},
function(response) {
console.log(response);
if ( response.error != undefined ){
$("#result").text(response.error.message);
return;
}else{
$("#result").text("succesfull shared "+response.id);
}
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object: response.id
})
}, function(r){});
});
}
i'm looking for some solution/alternative and with some example. i'm blocked there from 3 day and i can't find any other solution.
tHANKS
Solved with a dynamic url that generate dynamic og via php.
It's the only solution to have personalizedcontent and don't have problem with google/facebook cache!
You can see the result on the same page linked in OP

Facebook API How To Get All Pages I Like Without Pagination

If I like more than 100 pages/things, FB.API('me/likes') returns 99 items and a link to the next paging.
Is it possible to get ALL without the pagination?
Thanks
Have you tried /me/likes?limit=999 ?
You may still need to paginate, but you should be able to get more than 99 items in a single call
Use FQL:
$fql = "SELECT page_id from page_fan where uid = me())";
$pages_i_liked = $facebook->api(array(
'method'=> 'fql.query',
'access_token' => $access_token,
'query'=> $fql,
));
print_r($pages_i_liked);
Get All facebook pages of a user using facebook api
required permissions: manage pages
type: GET
url: https://graph.facebook.com/me/accounts
param: access_token
responce of the above request like this
{
"data": [
{
"category": "Book",
"name": "Mind blowing books",
"access_token": "CAACEdEose0cBAFRU2j0rGgNxBcJvU0pkZCpDbI7rZCJNmO2cZAfZBXoejoZCdTVdKi4gNCyBuu9fPRnWRAwCKrmkPePzKHoE5e46Jz7gRDYe3PM5ECm0ZC5OZB2iWLeEh3OZBgTGfWDmQbbFivwlp5v2umc0CcC9JlTvHsWDnTZCkKIbZAJeD2nOus1ZCCXMqSXHOAZD",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
],
"id": "618353601555775"
}
],
"paging": {
"next": "https://graph.facebook.com/100000328561058/accounts?access_token=CAACEdEose0cBADKMTNRBl5pjNhw8xsKnQf57XKShV7UlhGyJy67bBZCUKkepl9rELlxqq0I474f8LEPGnt51Mdgs0MMtgTycuUgkOyRnLgVypWVpBd7oKy3LXrrbsQWSdIUZBU4qKHLxSb14TP8ySOaZChLseseYMr1YMLG3qrJiWLuwWJeVz2PeE8TmkkZD&limit=5000&offset=5000&__after_id=618353601555775"
}
}
Post at specific facebook page of a user using facebook api
required permissions: piblish action
type: Post
url: https://graph.facebook.com/{PAGE_ID}/feed
param: access_token, message
this http request will write your message on fb page
PAGE_ID: its page id which is in responce of first request
The maximum results limit is 100
"I just noticed this while counting the results and also next page query, if I insert limit 999 for example, the exact results will be shown as 100 and the next link generated by facebook will contain the limit value also 100"
With this class from Github: FacebookLikedPagesAPI you can get all ID liked pages on Facebook without pagination
$access_token = '';// your access token here
$likes=new Likes();
$result=$likes->getAllLikedPages($access_token);