Facebook breaking changes Feb | Authenticated referrals going away - facebook-login

I have developed a Facebook game, and it requires authentication when a player loads the game. Previously it was working fine. Whenever a "new" user try to play my game, he needs to click on "allow" button to give the permissions. This dialog was working fine previously but now Facebook is going to apply some changes, known as Feb 2013 breaking changes.
When I "Enable" the February 2013 breaking changes through Facebook setting of my app, my application didn't work for existing and new users. In fact the "allow" permission dialog is not loading.
Previously I was successfully using the following method for authentication, which is not working now when I enabled the Feb 2013 breaking changes via game setting.
https://www.facebook.com/dialog/oauth? (link1)
Now I also tried to use another method for authentication
https://graph.facebook.com/oauth/authorize? (link 2)
but it didn't work either. The application is not redirected to app canvas page. In fact I got an error code 307 twice, and then it redirects the page to (link 1)
which is not working.
Could you please help me what is happening, and how could I make my authentication work?

Authenticated referrals are gone, so you need to think of an alternative way to ask your users for permissions. You can use the javascript SDK for that. You need to load the SDK first:
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
Then you need to init your application:
window.fbAsyncInit = function()
{
FB.init({
appId:'YOUR_APP_ID',
status:true,
cookie:true,
xfbml:true
});
};
Finally you have to create a login function, that will handle your custom logics:
function login()
{
FB.login(function(response){
if(response.authResponse)
{
//CUSTOM CODE GOES HERE
}
},{scope:'publish_actions'});
}

Related

Open Website From App And Redirect Back

We have an app that requires a user to make a payment. We have a third party provider that handles the payments. On our website, when the user makes a payment they get directed to the payment portal on the third party's website and after payment, they get redirected back to our website.
I have been tasked to implement the same thing in our iOS Swift 3 app. I have an idea of what I want to do but I am not quite sure how to do it. I started by thinking that I could open the user's browser with a POST request (I know now that I can't) and then using Universal Linking, grab the redirect with the app once payment is complete.
So since I cannot do POST requests on the user's browser, I thought I would implement a UIWebView in my app. Basically I have the code to do this. My question is. How do I capture the redirect from the UiWebView? As far as I can tell, upon successful payment the UIWebView will stay active and the page will redirect, showing our website inside of our app. This is not what I want.
Can anyone explain a better way of doing this? No Code required, but will be greatly appreciated.
Yes, Its possible and many apps are doing the same.
There are various methods to do it but What I am doing, I can share.
I am opening payment page in webview and after success on payment page. The page is redirecting to Success page with SuccessURL. When SuccessURL/FailedURL(Predefined) started loading, I take user back to native app.
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.url == "sucessURL" {
//do whatever you want
return false
}
if request.url == "failedURL" {
////do whatever you want
return false
}
else {
return true
}
}

ASP.NET WebApi Identity Facebook login access denied

I'm building a ASP.NET (4.6) WebApi project and I'm using ASP.NET Identity to authenticate with Facebook, Google and Microsoft to my API. I have managed to authenticate with Google and Microsoft, but not with Facebook.
I'm using Visual Studio 2015
The problem is that I get access denied every time I authenticate. The scenario goes like this:
I make an API call to localhost:2975/api/Account/ExternalLogins?returnUrl=%2F&generateState=true through my browser.
I receive a link to my API for every external provider my API support. In the Facebook case I got localhost:2975/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=http%3A%2F%2Flocalhost%3A2975%2F&state=99...01
I go to that link with my browser, and gets redirected to the Facebook login page.
I authenticate to Facebook, and a dialog window appears and asks permission for the requested information about me.
I accept and gets redirected back to my API with the error "access_denied". localhost:2975/api/Account/ExternalLogin gets called.
I haven't figured out where the problem comes from, whether its some permission setting in my Facebook app, the Facebook user I log in with, or if the problem lies in the ASP.NET Identity template.
Regarding Facebook I have created a test app of my app, as well as pushed it as a live app. I can find the app on my Facebook profile, and I've removed it several times. My Facebook profile has the administrator role of the app. I have created test users, as well as added a friend of mine as developer/tester of the app. The problem remains. I read somewhere that there should be a pending request for the app that I should accept, but I haven't found any.
Regarding the ASP.NET Identity template the error is received very early in the process:
AccountController.cs:
public async Task<IHttpActionResult> GetExternalLogin(string provider, string error = null)
{
if (error != null)
{
// This is where the API comes in step 5 above
return Redirect(Url.Content("~/") + "#error=" + Uri.EscapeDataString(error));
}
if (!User.Identity.IsAuthenticated)
{
// This is where the API comes in step 2 above before it redirects me to Facebook login
return new ChallengeResult(provider, this);
}
ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);
// Untouched logic
// ....
}
When I use Google Chromes Network tool I can see that I gets redirected to this link:
facebook.com/login.php?skip_api_login=1&api_key=XXX&signed_next=1&next=https%3A%2F%2Fwww.facebook.com%2Fv2.6%2Fdialog%2Foauth%3Fredirect_uri%3Dhttp%253A%252F%252Flocalhost%253A2975%252Fsignin-facebook%26state%3D...%26scope%3Demail%252Cpublic_profile%26response_type%3Dcode%26client_id%3D...%26ret%3Dlogin%26logger_id%3D...&cancel_url=http%3A%2F%2Flocalhost%3A2975%2Fsignin-facebook%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%26state%3D...%23_%3D_&display=page&locale=sv_SE&logger_id=...
There is a cancel url with predefined error: "access_denied", error code: 200, reason: "user_denied", so maybe the "access_denied" error I receive isn't very accurate?
Other relevant code I can come up with is in Startup.Auth.cs (I never get to the OnAuthenticated part though):
var facebookOptions = new FacebookAuthenticationOptions()
{
AppId = "XXX",
AppSecret = "XXX",
Scope = { "email", "public_profile" }
};
facebookOptions.Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new Claim("urn:facebook:access_token", context.AccessToken, ClaimValueTypes.String, "Facebook"));
context.Identity.AddClaim(new Claim("urn:facebook:email", context.Email, ClaimValueTypes.Email, "Facebook"));
return Task.FromResult(0);
}
};
app.UseFacebookAuthentication(facebookOptions);
It feels like I've tried everything. Any ideas on how to solve this?
Thanks in advance!
Update NuGet packages solved my issue.
From this post in the line
context.Identity.AddClaim(new Claim("urn:facebook:email", context.Email, ClaimValueTypes.Email, "Facebook"));
the context.Email is null.
try to update the nuget package which Microsoft.Owin.Security,Microsoft.Owin.Security.Facebook and so on
Those who were unable to resolve the issue by just updating nuget packages, it might help.
Our Web App was working fine with External Login, what was happening before was our app redirected the users to Facebook or Google for authentication and returned the relevant details from their account. But then this issue arises in which the redirect url contains an error with a value Access_Denied. which is not descriptive at all so you need to manually find the errors.
After a lot of debugging and nuget updates I was still unable to resolve the issue and then it turned out the solution was the IP whitelisting for the server as our IT team and few developers changed the the server settings or migrated the website to new server which obviously had a different IP. Hence, I added the IP address in Facebook dev console to whitelist the address and it worked like a charm.
Whereas, Google authentication was fixed without whitelisting anything, just updating the nuget packages did the job.

Facebook API: Post on Facebook wall is not working

I'm a Facebook app developer. I have developed some apps. Everything was working good.
I have not developed any apps for the past 6 months. Now I started to develop an app with existing code. It is not working like what I expected. I don't know why. I have checked the coding with old apps. Everything is fine.
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
} else {
loginUrl = "https://www.facebook.com/dialog/oauth/?client_id=" + appId + "&redirect_uri=https://apps.facebook.com/appname/&scope=email,user_activities,user_likes,publish_actions,read_stream,publish_stream";
top.location.href = loginUrl;
}
}, true);
I couldn't post on my facebook wall. Error ((#200) The user hasn't authorized the application to perform this action) is coming.
Please advice.
The authorization did not work. Use FB.login for authorization: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.1
Important note: Call it on user interaction, and NOT in the (asynchronous) callback function of FB.getLoginStatus. You should not directly present the authorization screen/popup to the user right when he opens your App/Website anyway.
Also, publish_stream is deprecated, publish_actions is the only permission you need for posting.

Without using cordova plugin post message on Facebook

Using this link facebook-phonegap-cordova-without-plugin I create an phonegap Facebook app. In that app application when I am login that application it working fine. It give me facebook friendlist, birthday, friend links and its allow to me to post on Facebook wall me and my friends Facebook wall. but when I logout and logging into another user then it allow me to login but its gives me that message The User hasn’t authorized the application to perform this action. And when I try to post some thing then it gives me that error This does not let testing post to Facebook your public profile is you name, profile and other public info
I am using
latest cordova build
In developer.facebook my application name is Testing
I am using API v1.0
following code is to share the post
function share() {
openFB.api({
method: 'POST',
path: '/me/feed',
params: {
message: 'Testing Facebook APIs',
},
success: function() {
alert('the item was posted on Facebook');
},
error: errorHandler});
}
Please remember its working fine for me but when I logging using another user then it gives me error.
Have you tried this while logging out the first user :
Revoke permissions :
openFB.revokePermissions(
function() {
},
errorHandler );
If it's working for you only then check if your app is in developer mode or not.
Go to your app facebook dashboard.
App review tab.
Check and turn on to make your app public.
Hope it helps with your question.

Why is the Facebook API returning an empty array for albums?

I'm fairly new to the Facebook API, but I've tried to do my due diligence to figure this out, but I can't seem to. I'm simply trying to get a list of the logged-in user's albums, using various techniques, to no avail. I'm using the JavaScript SDK, and I have the following code:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'{MY_APP_ID}',
cookie: true,
status: true,
xfbml: true,
oauth : true
});
FB.login(function(response) {
if(response.status === 'connected') {
FB.api('/me/albums', function(response) {
console.log(response);
});
}
}, { scope : 'user_photos' });
</script>
Note that {MY_APP_ID} is actually my application ID. So, when this executes, the popup will request access to the users photos, and that works fine. Now, in code, response returns a data array that contains no elements. In addition to trying the above, I've tried initiating a JSON request to the following URL as well as directly visiting it in the browser:
https://graph.facebook.com/me/albums?access_token=" + response.authResponse.accessToken
And this returns an empty data array as well. The access token that I'm using is coming either from the FB.login method or FB.getLoginStatus. Any help would be greatly appreciated. Thanks in advance.
So, I figured it out, so I will answer my own question. All the other answers on SO was related to permissions, but this wasn't it. It turns out that if I looked at my account settings (I'm the 'user'), and looked at apps, for this application, for some reason, it showed it only was requesting the email address. I knew this wasn't correct, because I was clearly asking for user_photos as well. So, after deleting the application from my profile, and reinitiating the connect, it looks like I'm able to access the albums fine. I'm not sure if Facebook intended to do this by design, but it seems like a potential bug to me.
This can also happen if you're using the JS SDK, as that authentication process and auth dialog are apparently complete separate from what you set up in the developer app.
You need to ALSO include the permissions you desire when you call FB.login() using the optional scope parameter, eg...
FB.login(function(response) {
if (response.authResponse) {
M.FB.setIsAuthorised(true);
// On success.
} else {
// On failure.
}
}, {
scope: 'email,friends_birthday,user_photos,friends_photos,publish_actions'
});
I had a similar issue. Several solutions on stackoverflow mostly attributed the issue to the lack of required permissions. Check the permissions you need by using the Graph API explorer or documentation (The tables have a column called permissions for each field).
Jonathan's solution actually gave me a clue about where I went wrong. I had a different issue where I had double-checked all the permissions set for my app dashboard that were correct, but while logging in, I had specified a scope with a set of permissions which seemed to override the app settings. :( I found this strange, but I rectified it by including the other permissions in the scope too and my problem was resolved.
An effective way to see if the right permissions are being set through the code is to use the following code:
FB.api({ method: 'fql.query', query: 'SELECT user_status,friends_status,user_photos,friends_photos,user_location,friends_location FROM permissions WHERE uid=me()' }, function(resp) {
for(var key in resp[0]) {
if(resp[0][key] === "1")
console.log(key+' is granted');
else
console.log(key+' is not granted');
}
});
P.S: Also make sure that if you changed the permissions in the app dashboard, you log out of your application and login again before testing.
I wasted over 3 hours trying to fix this issue and facebook documentation did not help me a bit, so hope this helps someone!