facebook.request("me") gives "OAuthException 2500" on Android

Corona’s Facebook API gives an “OAuthException 2500” error on Android.

Anyone know if this is a bug, or possibly a configuration error?

  1. [lua]facebook.login(facebookID, listener, {“publish_stream”})[/lua] works on both iPhone and Android:

[lua]event = {
type = “session”,
name = “fbconnect”,
expiration = “***”, – timestamp
phase = “login”,
token = “***”, – 114 chars
isError = “false”,
response = “”,
}[/lua]

  1. [lua]facebook.request(“me”)[/lua] works on iPhone, but fails on Android :

[lua]event = {
type = “request”,
name = “fbconnect”,
didComplete = “false”,
isError = “false”,
response = “{“error”:{“message”:“An active access token must be used to query information about the current user.”,“type”:“OAuthException”,“code”:2500}}”,
}[/lua] [import]uid: 73434 topic_id: 34494 reply_id: 334494[/import]

Olav,

I just tried our facebook sample app which does call [lua]facebook.request(“me”)[/lua]. It worked on my Android device.

The “OAuthException 2500” error indicates that your app has failed to log in and receive a token from facebook. Perhaps your app is making that facebook request too soon? Such as before your Lua listener has received a login success response?

I also suggest that you give our “Networking/Facebook” sample app a go with your app ID and secret key on Android. [import]uid: 32256 topic_id: 34494 reply_id: 137164[/import]

@Josh: Thanks for your quick response.

  1. I inserted my Facebook App ID into the Corona Facebook sample app as suggested:

[lua]build.settings:
CFBundleURLSchemes = {“fb0123456789”}

main.lua:
local appId = “fb0123456789”[/lua]

However, all I get from this is Facebook saying on the device screen: “An error occured. Please try later.” The device log gives no error messages. This happened on both iPhone and Android. So I need more help if I am to follow this line.

  1. You wrote, “Perhaps your app is making that facebook request too soon”. So in my own project code, I tried adding a timer before calling facebook.request(“me”), but the error still occurs.

[import]uid: 73434 topic_id: 34494 reply_id: 137191[/import]

I’m thinking that this must be a configuration issue on your facebook developer page. The vast majority of our facebook related tech-support issues usually are.

Have a look at the following blog post. It provides instructions on what needs to be filled out in the facebook developer page.
http://www.coronalabs.com/blog/2012/07/25/faq-wednesday-your-facebook-questions/

Make sure to enable the “Facebook Login” under the Native Android App section to enable SSO (Single Sign-On).

Also, if your Key Hash is wrong (which is the most common tech-support issue we get), then the Android log should tell you what key hash it was expecting. You can copy and paste that to your facebook developer page, which the above blog provides instructions for.

If you also want to support “app requests” and “deep linking”, then you’ll also need to fill out…

  • Package Name
  • Class Name (Must be set to “com.ansca.corona.CoronaActivity” without the quotes.)
  • Canvas URL
  • Secure Canvas URL
  • Mobile Web URL
  • Set Deep Linking to Enabled
    [import]uid: 32256 topic_id: 34494 reply_id: 137231[/import]

I read through all that, and can’t see anything wrong.

My Facebook “Native Android App” settings are as followings:

  • Package Name: (Same as “Package” in Corona Android Build Settings)
  • Class Name: com.ansca.corona.CoronaActivity
  • Key Hashes: (I got this error earlier, but fixed it, so it’s not this.)
  • Facebook Login: Enabled
  • Deep Linking: Disabled

Do you have a Facebook Test App you know is working that I can test against?

Or other suggestions?

[import]uid: 73434 topic_id: 34494 reply_id: 137237[/import]

Our sample app “Network/Facebook” that is included with the Corona SDK definitely works for me. I tried it yesterday with my personal appID using daily build #996.

I hate to ask this question, but are you sure your Android device has Internet access?
Can you access facebook via the official facebook app on your Android device?

Also, I’ve noticed that your app ID has the letters “fb” in front of it. All of the app IDs that I’ve seen from facebook contain only numbers. Perhaps you’ve copy and pasted the wrong ID? Your app ID should be at the top of the “Settings\Basic” facebook developer page. [import]uid: 32256 topic_id: 34494 reply_id: 137240[/import]

Aw! I had [lua]local appId = “fb0123456789”[/lua] rather than just [lua]local appId = “0123456789”[/lua]. Now the sample app works. Then I’ll just have to work out what’s wrong with my original project code. I’ll post my findings here.

PS! Since CFBundleURLSchemes wants “fb0123456789” and facebook.login() wants “0123456789”, you could consider making your API tolerant to Facebook App ID strings both with or without “fb”. Or at least give a warning.

[import]uid: 73434 topic_id: 34494 reply_id: 137255[/import]

I’m glad you got it working!

One question.
Does iOS successfully log in with an app ID starting with a “fb”?
Does that “fb” app ID only fail on Android?
(Guess that was 2 questions.)

I ask because I’m an Android developer here (not really set up for iOS) and I wasn’t aware of the “fb” prefix. If iOS accepts the “fb” prefix, then I can modify our Android code to strip it off before handing it over to the Facebook SDK.
[import]uid: 32256 topic_id: 34494 reply_id: 137410[/import]

The “fb” is part of the URL Scheme which is “fb” + “yournumericappid” + “optionalsuffix”.

They are different values and it might cause more confusion to allow you to use the URL Scheme where the specific AppID is needed. [import]uid: 199310 topic_id: 34494 reply_id: 137448[/import]

Olav,

I just tried our facebook sample app which does call [lua]facebook.request(“me”)[/lua]. It worked on my Android device.

The “OAuthException 2500” error indicates that your app has failed to log in and receive a token from facebook. Perhaps your app is making that facebook request too soon? Such as before your Lua listener has received a login success response?

I also suggest that you give our “Networking/Facebook” sample app a go with your app ID and secret key on Android. [import]uid: 32256 topic_id: 34494 reply_id: 137164[/import]

@Josh: Thanks for your quick response.

  1. I inserted my Facebook App ID into the Corona Facebook sample app as suggested:

[lua]build.settings:
CFBundleURLSchemes = {“fb0123456789”}

main.lua:
local appId = “fb0123456789”[/lua]

However, all I get from this is Facebook saying on the device screen: “An error occured. Please try later.” The device log gives no error messages. This happened on both iPhone and Android. So I need more help if I am to follow this line.

  1. You wrote, “Perhaps your app is making that facebook request too soon”. So in my own project code, I tried adding a timer before calling facebook.request(“me”), but the error still occurs.

[import]uid: 73434 topic_id: 34494 reply_id: 137191[/import]

I’m thinking that this must be a configuration issue on your facebook developer page. The vast majority of our facebook related tech-support issues usually are.

Have a look at the following blog post. It provides instructions on what needs to be filled out in the facebook developer page.
http://www.coronalabs.com/blog/2012/07/25/faq-wednesday-your-facebook-questions/

Make sure to enable the “Facebook Login” under the Native Android App section to enable SSO (Single Sign-On).

Also, if your Key Hash is wrong (which is the most common tech-support issue we get), then the Android log should tell you what key hash it was expecting. You can copy and paste that to your facebook developer page, which the above blog provides instructions for.

If you also want to support “app requests” and “deep linking”, then you’ll also need to fill out…

  • Package Name
  • Class Name (Must be set to “com.ansca.corona.CoronaActivity” without the quotes.)
  • Canvas URL
  • Secure Canvas URL
  • Mobile Web URL
  • Set Deep Linking to Enabled
    [import]uid: 32256 topic_id: 34494 reply_id: 137231[/import]

I read through all that, and can’t see anything wrong.

My Facebook “Native Android App” settings are as followings:

  • Package Name: (Same as “Package” in Corona Android Build Settings)
  • Class Name: com.ansca.corona.CoronaActivity
  • Key Hashes: (I got this error earlier, but fixed it, so it’s not this.)
  • Facebook Login: Enabled
  • Deep Linking: Disabled

Do you have a Facebook Test App you know is working that I can test against?

Or other suggestions?

[import]uid: 73434 topic_id: 34494 reply_id: 137237[/import]

Our sample app “Network/Facebook” that is included with the Corona SDK definitely works for me. I tried it yesterday with my personal appID using daily build #996.

I hate to ask this question, but are you sure your Android device has Internet access?
Can you access facebook via the official facebook app on your Android device?

Also, I’ve noticed that your app ID has the letters “fb” in front of it. All of the app IDs that I’ve seen from facebook contain only numbers. Perhaps you’ve copy and pasted the wrong ID? Your app ID should be at the top of the “Settings\Basic” facebook developer page. [import]uid: 32256 topic_id: 34494 reply_id: 137240[/import]

Aw! I had [lua]local appId = “fb0123456789”[/lua] rather than just [lua]local appId = “0123456789”[/lua]. Now the sample app works. Then I’ll just have to work out what’s wrong with my original project code. I’ll post my findings here.

PS! Since CFBundleURLSchemes wants “fb0123456789” and facebook.login() wants “0123456789”, you could consider making your API tolerant to Facebook App ID strings both with or without “fb”. Or at least give a warning.

[import]uid: 73434 topic_id: 34494 reply_id: 137255[/import]

I’m glad you got it working!

One question.
Does iOS successfully log in with an app ID starting with a “fb”?
Does that “fb” app ID only fail on Android?
(Guess that was 2 questions.)

I ask because I’m an Android developer here (not really set up for iOS) and I wasn’t aware of the “fb” prefix. If iOS accepts the “fb” prefix, then I can modify our Android code to strip it off before handing it over to the Facebook SDK.
[import]uid: 32256 topic_id: 34494 reply_id: 137410[/import]

The “fb” is part of the URL Scheme which is “fb” + “yournumericappid” + “optionalsuffix”.

They are different values and it might cause more confusion to allow you to use the URL Scheme where the specific AppID is needed. [import]uid: 199310 topic_id: 34494 reply_id: 137448[/import]

OK, I finally found the problem with Facebook and Android.

[lua]-- Works on iPhone and Android.
facebook.request(“me”)

– Works on iPhone. Fails on Android.
facebook.request(“me?fields=id,name,first_name,gender”)[/lua]

From what I can understand, adding the “fields” parameter causes the Facebook request to fail on Android.

Then I tried adding the access token manually, and then I got the following error message:

[lua]facebook.request(“me?fields=id,name,first_name,gender&access_token=”…event.token)

– {“message”:“Malformed access token BAAEMi9…?access_token=BAAEMi9…”,
– “type”:“OAuthException”,
– “code”:190}[/lua]

Notice that Facebook complains that the access token is $TOKEN?access\_token=$TOKEN. Could this be a revelation of the problem? That Corona somehow makes an error in generating the URL it sends to Facebook? That would explain the initial “2500” error too.

My suspicion is that Corona simply adds access\_token=$TOKEN to the URL prefixed by a ? rather than a &. It makes sense:

[lua]“me” – becomes “me?access_token=$TOKEN”
“me?fields=id” – becomes “me?fields=id?access_token=$TOKEN”
“me?fields=id&access_token=$TOKEN” – becomes “me?fields=id&access_token=$TOKEN?access_token=$TOKEN”[/lua]

I hope someone technical at Corona can take a look at this as soon as possible, as I need to specify the fields parameter. [import]uid: 73434 topic_id: 34494 reply_id: 138715[/import]

Have you tried this:

local params = {  
 fields = "id,name,first\_name,last\_name,email,username,picture"  
 }  
 facebook.request("me", "GET", params)  

That works for me. [import]uid: 199310 topic_id: 34494 reply_id: 138719[/import]

I assumed you could indicate full Graph URLs (like me?fields=id) in the path argument. That actually works in iOS, but as we have seen fails on Android with misleading error messages.

Anyway, problem solved on my part.
[import]uid: 73434 topic_id: 34494 reply_id: 138767[/import]