Spotify FB Login with preview api - facebook

Anyone knows how the facebook login works with the new preview spotify apps api?
I tried something like this...
require(['$api/facebook'], function(facebook) {
facebook.session.showConnectui();
}
but nothing got me to the result I got with the old api. I also tried to use plain FB js sdk, but the problem is it needs some "url" to allow connections...wich I can't really give out of the spotify app?
Any ideas?

The auth module was not present at first, but now it is part of the Spotify Apps API. You can read more about it on its documentation page. It looks like this:
require(['$api/auth#Auth'], function(Auth) {
var appId = '<your_app_id>',
permissions = ['user_about_me'];
var auth = new Auth();
auth.authenticateWithFacebook(appId, permissions)
.done(function(params) {
if (params.accessToken) {
console.log('Your access token: ' + params.accessToken);
} else {
console.log('No access token returned');
}
}).fail(function(req, error) {
console.error('The Auth request failed with error: ' + error);
});
}
});
In addition, there is a working example in the Tutorial App on GitHub.

Related

How to get the Authentication Provider for actions-on-google on Node using account linking with Auth0?

I have Javascript App running under Node v8.11.2 which uses the Actions-On-Google library. I'm using the V2 API. I have account linking set up with Auth0 and am using the SignIn helper intent. Auth0 is set up to use Google, Facebook and Twitter.
The scopes I use are OPENID, OFFLINE_ACCESS, PROFILE and EMAIL.
Everything is working fine and when the User is authenticated I get an Access Token returned.
My question is, how do I get the Authentication Provider that was selected by the User so that I can use the Access Token correctly to retrieve profile elements such as the display name, email address etc??
The signin object passed to the Sign In Confirmation intent handler just contains the following regardless of the provider selected: -
{"#type":"type.googleapis.com/google.actions.v2.SignInValue","status":"OK"}
Any help greatly appreciated as I have a deadline and this is driving me a bit crazy now!
Thanks,
Shaun
If your question is about how to get the required information when you have your accessToken available then you could use what is shown in this answer.
In node this looks like that:
let link = "https://www.googleapis.com/oauth2/v1/userinfo?access_token="+accessToken;
return new Promise(resolve => {
request(link,(error, response, body) => {
if (!error && response.statusCode === 200) {
let data = JSON.parse(body);
let name = data.given_name ? data.given_name : '';
conv.ask(new SimpleResponse({
speech: "Hello "+ name + "!",
text: "Hello "+ name + "!"
}));
resolve();
} else {
console.log("Error in request promise: "+error);
resolve();
}
})
})
Everything you need should be in the data object.
Hope it helps.

Get public photos from facebook using xamarin.Social

Can anyone help me to get public photos from a Facebook page. I'm developing a mobile app using Xamarin.Forms in which I need to get public photos from Facebook.
Currently I'm using Xamarin.Social to integrate Facebook in the app and I'm able to login into a Facebook account but not able to get public photos.
Use the Xamarin.Auth to query the relative facebook API link. For Example, to get the user name and ID you can use:
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/v2.4/me"), null, _currentUser);
await request.GetResponseAsync().ContinueWith(t =>
{
if (t.IsFaulted)
return;
else
{
string mail = t.Result.GetResponseText();
Dictionary values =
JsonConvert.DeserializeObject>(mail);
bool s = values.TryGetValue("name", out _name);
bool i = values.TryGetValue("id", out _userId);
if(!s){
_name = "Error Getting Username";
}
if(!i){
_userId = "Error Getting Id";
}
}
});
To explore the Facebook API you can follow this link
Hope this helps.

facebook c# SDK get albums and images

what i am trying to achieve should be simple by theory but hell by implementation, if you think otherwise please help.
so what i am trying to achieve here is that I have my facebook page which I created a developer acount for it, and what i want is to take albums from the page to my website.
I am using the latest stable facebook sdk for .net 6.8.0, and i am assuming that the graph api is on v2.2.
this is the code i am using below to get the access token and access my albums
try
{
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "---my application number---",
client_secret = "---my application secret---",
grant_type = "client_credentials"
});
var fb2 = new FacebookClient(result.access_token);
dynamic albums = fb2.Get("my application number/albums");
foreach (dynamic albumInfo in albums)
{
try
{
dynamic albumsPhotos = fb2.GetTaskAsync(albumInfo.id + "/photos");
}
catch (Exception Exception)
{
throw Exception;
}
}
}
catch (Exception e)
{
throw e;
}
The data returned in the dynamic albums variables is empty, the thing that confused me more is when i use facebook graph api explorer the call work fine and it return the albums. so what exactly i am missing.
I also read in some threads that you can access your albums without the secret password if they are public but that didn't work for me either i tried it in javascript but no joy.
Thank you in advance.
Since this is your page, it should be pretty easy to retrieve your own photos using Windows PowerShell and http://facebookpsmodule.codeplex.com Get-FBAlbums.

facebook with action script 3 issue in retrieve friends

I develop simple facebook game using action script 3 ,, I have an issue
-- first when I logged with Admin of the game or developer ,, I can get my profile and my friend list . and if I login to facebook with any user failed to retrieve user and friends O_O
is that permission issue or what?
-- second issue I need to make my app ask for permission before loading swf ,, how can I do this?
my code:
public function FaceBookData()
{
Facebook.init(APP_ID, HandleFacebookConnect);
}
private function HandleFacebookConnect(success:Object, fail:Object):void
{
if(success)
{
accessToken =params["access_token"] = Facebook.getAuthResponse().accessToken;
Facebook.api("v2.0/me/invitable_friends", RetrievedFriends, params);
Facebook.api("v2.0/me", RetrievedMe, params);
}
else
{
Facebook.login(HandleFacebookConnect,{perms: 'public_profile,email,user_friends'});
}
}

JS SDK getLoginStatus doesn't return userID nor signedRequest

I'm using PhoneGap/Cordova with the facebook plugin. Everything seems to work except for getLoginStatus who is not working as defined here and here. When called, it returns some data, but not all: it doesn't return userID nor signedRequest.
Here is the code:
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
var fb_uid = response.authResponse.userID;
var fb_signedRequest = response.authResponse.signedRequest;
alert('logged in');
} else {
alert('not logged in');
}
});
userID is filled with ellipsis (...), while signedRequest is undefined.
I managed to get userID with a graph call to /me:
FB.api('/me', function(me){
if (me.id) {
var fb_uid = me.id;
}
});
I wasn't able to find any way in the documentation to get a signed_request, which I have to use to authenticate the facebook user to a remote service to whom the user already connected to with facebook (I already made a login call so user is OK).
Basically the problem is that my call to getLoginStatus returns
{
status: 'connected',
authResponse: {
session_key: true,
accessToken: 'a long string...',
expiresIn:'a number',
sig: '...', //exactly this string
userID:'...' //exactly this string
secret:'...' //exactly this string
expirationTime:'a long number'
}
}
instead of what documented
As a background, when authentication happens using the plugin then the JavaScript SDK API calls the iOS/Android SDK to handle the authorization and then pass response auth data back to the JS part. The native (iOS/Android) SDKs do not get signed requests back to be able to pass this on to the JS. This is why it's empty.
If you use the latest plugin you should at least now be seeing the user ID. The one from June likely did not pass this back. Otherwise as a work around, you could perform a call to the /me endpoint when authentication is successful in your JS code to get the user id. See the Hackbook example that does this.