Invited friends aren't getting apprequest invitations, Facebook API-SDK - facebook-javascript-sdk

Hi I'm sending app requests invitations and my facebook friends aren't getting nothing. I'm using the Facebook API is loading perfectly in my page I can connect , retrieve the basic fb data, email and stream publish ... and right now I'm trying to send invitations from the same page using this code
PIGSKIN.inviteFBfriendsToGroup = function () {
//console.log("invite FB friends");
FB.ui({
method: 'apprequests',
message: 'Invita a tus amigos a unirse al PigSkin Caliente',
display: "iframe"
},function (response) {
console.log("Response", response);
var friends = response.to;
if (friends.length > 0) {
FB.ui({
method: 'apprequests',
message: 'Te invito a unirte al PigSkin de Caliente',
to: friends.join(","),
link: location.href,
new_style_message: true
}, function (response) {
console.log("Response here ", response);
});
}
});
};
I'm opening the apprequest dialog to select friends and invite them ,then I confirm the invitation request ..
and it responds me this
the response object seems correct I guess ... but checking with my fb friends they didn't receive any invitation ... is this a facebook issue ? or I'm doing something wrong
Sorry I forgot to post my login:
FB.login(function (response) {
if (response.status === 'connected') {
PIGSKIN.FBconnect(); //Don't worry about this function ...
}
},{scope:"email,publish_stream,publish_actions"});
Thanks
Facebook documentation
https://developers.facebook.com/docs/reference/dialogs/requests/

your FB.ui function is working perfectly, i've replicate the documentation example with your FB.ui code and the result was successful... Maybe it's facebook, or maybe the permissions on Caliente's fb-page... can't tell... Good luck.

Related

Unable to get access Token linkedin Oauth

I know some will put comment like this post is duplicate of so many questions, but I've tried many ways to achieve Access Token in linkedin Oauth. Explaining what i tried.
1) I'm following it's official doc's Linkedin Oauth2
2) I'm successfully getting Authorization code from step 2 and passing that code to step 3 for exchanging Auth code for getting Access Token. But i'm getting following error
{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired","error":"invalid_request"}
3) According to some links i need to set content-type in the header.Link which tells to set content-type is missing
4)Then i tried calling https://www.linkedin.com/uas/oauth2/accessToken this service instead of POSt to GET. And passing data as queryParams.
5) Some link says oauth code expires in 20 sec, So i've checked, i'm making call for access token in less that 1 sec.
6) And if i pass data in Body params like as below and used url as https://www.linkedin.com/uas/oauth2/accessToken
var postData = {
grant_type: "authorization_code",
code: authCode,
redirect_uri: 'https%3A%2F%2Foauthtest-mydeployed-app-url',
client_id: 'my_client_id',
client_secret: 'secret_key'
};
7) With Get call my url i tried
https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code='+authCode+'&redirect_uri=https%3A%2F%2Foauthtest-mydeployed-app-url&client_id=my_client_id&client_secret=secret_key
Still i'm getting Error even though status code is 200, i'm getting that error(with GET api)
and If POSt by passing postData in body i'm getting bad request 400 status code
Not understanding why m I not getting access code. I've read many solutions.
Sharing code as requested.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast"
], function (Controller, MessageToast) {
"use strict";
return Controller.extend("OauthTest.OauthTest.controller.View1", {
onPress: function (evt) {
var sPath =
'https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=my_client_id&redirect_uri=https%3A%2F%2Foauthtest-mydeployed-app-url&state=DCEeFWf45A53sdfKef424&scope=r_basicprofile';
window.location.href = sPath;
var oRouter = new sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("View2", {
"username": "Test"
});
MessageToast.show(evt.getSource().getId() + " Pressed");
},
//after user allows access, user will be redirected to this app with code and state in URL
//i'm fetching code from URL in below method(call is happening in max.569ms)
onAfterRendering: function () {
var currentUrl = window.location.href;
var url = new URL(currentUrl);
var authCode = url.searchParams.get("code");
if (authCode !== undefined && authCode !== null) {
var postData = {
grant_type: "authorization_code",
code: authCode,
redirect_uri: 'https%3A%2F%2Foauthtest-mydeployed-app-url',
client_id: 'my_client_id',
client_secret: 'secret_key'
};
/* var accessTokenUrl = 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=' + authCode +'&redirect_uri=https%3A%2F%2Foauthtest-mydeployed-app-url&client_id=my_client_id&client_secret=secret_key';*/
var accessTokenUrl = 'https://www.linkedin.com/uas/oauth2/accessToken';
$.ajax({
url: accessTokenUrl,
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
},
data: postData,
success: function (data, textStatus, jqXHR) {
console.log(data);
alert('success');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
alert('error');
}
});
}
}
});
});
Help will be appriciated..!!!
Finally I am happy to post my answer after so much search.
Every step I did is correct only, but one thing I was missing here like, Linkedin API doesn't supports CORS.
I tried implementing Javascript SDK, that works like charm. But API wasn't.
Then I found very helpful Link which says I need to implement Rest API from backend by allowing CORS, not from front end.
Make sure to follow all the points which I mentioned above in my post.
And for Allow CORS follow this link. You will get data but only basic profile of user according to LinkedIn Terms data can be accessible
Hope this post may help someones time to search more

Retrieve Google+ activity list of an user

I need to get the list of activities of an user in Google+. My coding platform is node.js Express framework and I'm using google-api-nodejs-client package.
var googleapis = require('googleapis');
var auth = new googleapis.OAuth2Client();
var accessToken="XXXXXX......";
googleapis
.discover('plus', 'v1')
.execute(function (err, client) {
if (err) {
console.log('Problem during the client discovery.', err);
return;
}
auth.setCredentials({
access_token: accessToken
});
client
.plus.people.get({ userId: 'me' })
.withAuthClient(auth)
.execute(function (err, response) {
console.log('My profile details------>', response);
});
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
})
.withAuthClient(auth)
.execute(function (err, response) {
console.log('err----------------------------->',err);//EDIT
console.log('activities---------------------->', response.items);
});
});
I got my profile details. But the activity is returning value: null. I checked my Google+ page to make sure that I have public posts. Also, I shared some posts to 'public' myself. Please help me find the bug in my code.
EDIT
Actually, there is an error. I found it by logging the value of err object in console as advised by Ryan Seys.
err--------------->
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
It would help if you provide the value of the err object but here's a few thoughts:
Do you have Google+ API turned on for your project? See https://console.developers.google.com/ and the APIs and auth section of your project to enable the API.
Are you requesting the right scopes for user profile data. See https://developers.google.com/apis-explorer/#p/plus/v1/plus.activities.list to try out the request. Click the OAuth button on that page to see the different types of scopes you may like to try requesting from the user. Some of the scopes I see right now are:
https://www.googleapis.com/auth/plus.login (Know your basic profile info and list of people in your circles).
https://www.googleapis.com/auth/plus.me (Know who you are on Google)
https://www.googleapis.com/auth/userinfo.email (View your email address)
https://www.googleapis.com/auth/userinfo.profile (View basic information about your account)
Try adding an empty body field to the API request. This is a caveat of the current API client and some requests require you to enter a default empty {} after the parameter object.
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
}, {}) // <--- see the extra {} here!
.withAuthClient(auth)
.execute(function (err, response) {
console.log('activities---------------------->', response.items);
});
I think the problem is that you are specifying an empty fields parameter to client.plus.activities.list() instead of not providing a fields parameter at all. This tells it to return no fields for the results. Since the fields parameter is optional, you can omit it completely.
Try something like:
client
.plus.activities.list({
userId: 'me',
collection: 'public',
maxResults: 100
})

Cannot Checkin Through FB.api (javascript)

With the javascript sdk (FB.api), I cannot checkin on behalf of user.
(The user has granted publish_stream permission to my app)
Since facebook's API keeps changing, confused for some time. After searching and reading from internet, I think it's the right way to publish a checkin. Any help is appreciated.
var params = {
method: 'POST',
place: 107297282684980,
message: 'hi',
coordinates: {
'latitude': 22.204284439454,
'longitude': 113.54313260065
}};
FB.api(
'/me/checkins',
params,
function(response) {
if( response )
alert('Checkin Completed!');
});
It was deprecated at July 2013. You should check the changes from the URLs provided at the question comment.
And follow the instructions:
https://developers.facebook.com/docs/opengraph/overview/
https://developers.facebook.com/docs/opengraph/getting-started/
As FB Check-In is deprecated we can achieve the same thing with a post on FB with Location Attached using the following FB Graph Api post.
FB.api('/me/feed', 'post', {
name: 'SomeName',
message: 'SomeMessage',
place: yourLocationID
}, function (response) {});
Note : Where yourLocationID is the ID that you will get by the Graph search using https://graph.facebook.com/search?q=yourPlaceName&type=page&access_token=YOURTOKEN

How do I post a "I just registered at..." story to a user's timeline immediately after they register for my site through FB?

Thought this would be an easy one...
My site uses OAuth to allow users to login and register for the site through FB, which returns an access token for the user. I've been playing around with Open Graph to get this registration post to work, and have successfully posted a story to my timeline using the examples in the documentation (https://developers.facebook.com/docs/opengraph/getting-started/), but I can't seem to integrate it with my actual site.
This is the modified code I used from the example to post the story:
FB.api(
'https://graph.facebook.com/me/feed',
'post',
{
message: "I just registered for X!",
name: "Example",
description: "Yay I did it!",
caption: "Woo hoo!",
picture: "http://www.example.com/images/img.png",
link: "http://www.example.com/"
},
function (response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
alert('Error: ' + response.error.message);
}
}
);
Is there a way to automatically post this story to a user's timeline upon site registration through FB? Does the access token that's returned by OAuth give me permission to do this? I tried passing the access token retrieved by OAuth into the post call, but got the "user did not give you permission to do this" message:
FB.api(
'https://graph.facebook.com/me/feed',
'post',
{
access_token: "#ViewBag.Token",
message: "I just registered for X!",
name: "Example",
description: "Yay I did it!",
caption: "Woo hoo!",
picture: "http://www.example.com/content/images/img.png",
link: "http://www.example.com/"
},
function (response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
alert('Error: ' + response.error.message);
}
}
);
Or do I need to prompt the user to give me this specific permission after they've registered, and then have them click the "create story" button to publish the story to their timeline like the online example shows (https://developers.facebook.com/docs/opengraph/getting-started/)?

Fb.ui apprequest returning null response

After sending an Facebook app request in FB.ui using Javascript SDK, the response returned in the callback function is 'null', if the user sends the request or not. I have tested with multiple Facebook accounts and receive the app requests, however.
, sendRequest: function() {
parent.FB.ui({method: 'apprequests',
to: this.game.attributes.opponentFbId,
title: 'My App',
message: 'I sent you a challenge on My App',
}, function (response) {
console.log(response)
});
According to http://fbdevwiki.com/wiki/FB.ui, method 'apprequests' should return an array of request_ids (via response.request_ids), or response.to .However 'response' returns null when I try to log it in console
I have tried something similar with method 'feed' in FB.ui and can read the response (and response.post_id), however not with 'apprequests'.