android facebook login button does not work - facebook

I'm following this tutorial "Facebook Login Flow for Android" (https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/) to create a simple app containing only one facebook login button to test facebook login.
However, I've been having trouble logging in facebook with this button.... I've been following every step in this tutorial and I've double checked everything -- it is exactly the same as in this tutorial. I see other people who have similar problems are always because of incorrect debug hash code. But I've checked like a million times that I got the correct debug hash code. Some people say that if you wanna release an app, you need a release code. However, I'm not releasing my app -- I'm just testing it on an android device, so I guess I dont really need a release code to do that?
Also, I've checked that I've included my facebook application id for this app in the Android Manifest. So basically, everything I did was strictly following the tutorials on Facebook Developers.
I've seen some people suggesting to use the "keytool" in JDK 6 in stead of JDK 7. And I've checked that I actually did generate my debug hash code with the "keytool" in JDK 6.
So I've tried everything, but the problem still exists!
In that Android Tutorial, it suggests putting this in your code so that you can monitor your LogCat to see if your current state is logged in or logged out:
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
In my case, no matter how many times I clicked Facebook Login Button, I always got "Logged out..." in my LogCat.
Also, the funny thing is, I can't even log in facebook using those sample apps coming with Facebook Android SDK 3.0.1 (eg. SessonLoginSample)!!!!! When I click the login button in those sample apps, nothing happens -- which means I'm not successfully logged in.
I really hope you guys out there can help me with this problem. It's weird I don't see other people with the exact same problem (as I said, those with similar problems are always because of incorrect debug code, but I've checked mine, it is 100% correct). THANK YOU SO MUCH!

It happened to me once. You might have added the export key hash in facebook developer setting.
Add these lines to your code to get your debugging key hash and then add to facebook.
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}

Related

Unity Facebook sdk 4.3.6

I am having a issue with facebook login. I am using facebook sdk 4.3.6 and unity3d 4.3.0/4.3.1.
when I hit login button Facebook permission windows open and after pressing ok nothing happens and following message is printed in logs
" sending to Unity OnLoginComplete({"cancelled":true,"key_hash":"asdasd"}) "
FB.Login("email,publish_actions", LoginCallback);
and in
void LoginCallback(FBResult result)
{
login = result.Text; // output login=false, userid="", access_Token=""
}
Not sure what the above answer is...Why does JSON have to do with anything?
I am having the same problem...was using Facebook SDK 4.3.4 and was having the same problem.
I saw there was a new one up 4.3.6 and tried it...same problem.
I check LOGCAT and saw the same line:
sending to Unity OnLoginComplete({"cancelled":true,"key_hash":"4EbLC........0uFU1A="})
Which is NOT my has from my UNITY Facebook settings...I have no idea where it is getting this HASH from.
I am wondering if the "cancelled":true result is a result from the Facebook Dialog to allow permissions ..although I did not click CANCEL
I am going to try the only thing I haven't tried yet and that was a post from someone to get the latest OPENSLL and regen the keys...
SOLVED: OK Here is what I did to get it working....
I added that Hash that I got from the LOGCAT to the Facebook Develop App Settings on
develop.facebook.com/apps
Now it logs in me in...
I just don't know where that Hash is coming from...I also have the hash that was generated from Unity in there as well.
Ryan

unity3d 4.3 facebook SDK login

hi i have unity3d and the latest facebook sdk
i've downloaded the sample project but i got a problem, when i start the project and click login, unity immediately show this images:
which i expecting i've got an error from this part of code in mainmenu.cs
if (FB.IsLoggedIn)
{
string panelText = "Welcome ";
if (GameStateManager.Username != null) panelText += GameStateManager.Username + "!";
else panelText += "Smasher!"; //I GOT THIS ELSE BLOCK !
if (GameStateManager.UserTexture != null)
GUI.DrawTexture( (new Rect(8,10, 150, 150)), GameStateManager.UserTexture);
GUI.Label( (new Rect(179 , 11, 287, 160)), panelText, MenuSkin.GetStyle("text_only"));
}
which is my gamestatemanager.username is null... i just want to know why my gamestatemanager.username is null, how to get some data to fill that.. i've followed step to fill gamestatemanager.username in this link where's my error btw ? anyone can help ?
Please see this question. Unity Facebook SDK Login Always Returns User 0 Access Token abc...z We don't support the editor or desktop yet. You will have to run on an ios or android device, or publish your app to facebook canvas.
I think you are having the same problem I am...
It seems it has logged you in but returns USerID:0 and Access Token: abcdefghijklmnopqrstuvwxyz
I think this is a TEST User that is automatically logs in but I can't seem to find out how to turn that off and to actually have it log ME on.
Is your APP in Sandbox mode? I tried turning my sandbox mode in the facebook app settings off but it didn't seem to effect it...
Waiting for an answer on this and my related question...
Unity Facebook SDK Login Always Returns User 0 Access Token abc...z
If you are running this from the EDITOR then the reason is the EDITOR does not actually log you in.
If you are running from the device...I am still working on that one (also getting the same result you are)

Facebook friend dialog not working on mobile

Prologue:
I have about the same problem as described in the previously asked question (FB add friend dialog on mobile doesnt work).
But since there is no real solution to this problem made known other than the comment:
"it started working ... I didnt change anything." [...] (#dinodsaurus)
I'm asking it again. With some extra information specific to my case.
I'm using the facebook friend dialog by redirecting (302) to an URL like: (https://www.facebook.com/dialog/friends/?id=3500194&app_id=531355753613866&redirect_uri=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F19403197%2Ffacebook-friend-dialog-not-working-on-mobile%23success)
The above URL works fine on both a desktop and a mobile browser.
Facebook automaticly redirects the before mentioned URL to their m.facebook.com domain while using a mobile device/browser. This renders the display=touch version of the dialog (see dialog reference).
This all seems very normal (and is actually wanted behavior).
But... it goes wrong when I confirm that I want to send the friend request. And only when I confirm it using a mobile device.
The message that I get after confirming on my mobile is:
"Sorry, something went wrong.
We're working on getting this fixed as soon as we can."
(Be sure to use your phone's browser for the above link or directly visit m.facebook.com using this link to reproduce the error.)
OK, so I waited two days now since I sent a bugreport (I found out I actually didn't do it the right way but I guess it's already filed before) for this error to Facebook and it seems like there is no fix. Also it seems to me that it's not likely they leave this broken for such a long time. Unless...
Main question:
So my question is actually:
Does anybody know of any reason that Facebook might have for possibly not fixing this error? And if so, is there any way around this while still using a reasonable display style for mobile devices?
Examples of solutions are very welcome... ;)
Edit:
I just filed a Repro for this bug. If you can reproduce the error that I describe here please file a Repro yourself at: https://developers.facebook.com/bugs/309157325894924 so as to give this bug more priority.
As answered by Wimagguc in this question you may try this:-
The underlying problem is that the Facebook API is not yet ready for
all the display types, and the friends dialog cannot be shown for the
mobile display.
protected static String DIALOG_BASE_URL = "https://m.facebook.com/dialog/";
protected static String DIALOG_BASE_URL_FOR_MISSING_SCREENS = "https://www.facebook.com/dialog/";
public void dialog(Context context, String action, Bundle parameters,
final DialogListener listener) {
boolean missingScreen = action.contentEquals("friends") ? true : false;
String endpoint = missingScreen ? DIALOG_BASE_URL_FOR_MISSING_SCREENS : DIALOG_BASE_URL;
endpoint += action;
parameters.putString("display", missingScreen ? "popup" : "touch");
parameters.putString("redirect_uri", REDIRECT_URI);
if (action.equals(LOGIN)) {
parameters.putString("type", "user_agent");
parameters.putString("client_id", mAppId);
} else {
parameters.putString("app_id", mAppId);
}
if (isSessionValid()) {
parameters.putString(TOKEN, getAccessToken());
}
String url = endpoint + "?" + Util.encodeUrl(parameters);
if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
Util.showAlert(context, "Error",
"Application requires permission to access the Internet");
} else {
new FbDialog(context, url, listener).show();
}
}
Facebook decided that the bug has no priority and changed the status to "Won't Fix" at December 7th, 2013.
The original bug report was marked as a duplicate of https://developers.facebook.com/x/bugs/309157325894924/. See this page for more info.
I think this is a shame and I would still like to urge anyone who thinks the same to open a new bugreport for the issue. Or leave a comment on the report stated above. Since this seems to be the only way to create some sense of urgency for solving this problem.
PS: I recommend a bugreport since my comments were deleted lately.
PS2: Even my bugreport "to state the won't fix issue in the documentation" seems to be ignored. So every day new people will research the possibilities of a mobile web app with a connection to facebook and will wrongly assume they can use the "facebook friend dialog" in their web app on mobile devices. My hope is that they will find this page during their research, and steer clear off that assumption.

Phonegap Android Facebook plugin publish_stream permission request throws "Error calling method on NPObject"

I'm using Phonegap for Android and I have just integrated Facebook plugin(https://github.com/phonegap/phonegap-facebook-plugin) to my project. I need to get an AccessToken that could be sent to server so that server could post on user's behalf.
When I at first called FB.login(callback, {scope:'email,user_birthday,user_location'}) everything works fine and dandy. But if I add 'publish_stream' permission to the scope I get an error: "Uncaught Error: Error calling method on NPObject". Error is originating from cordova.js (phonegap 2.8) on line 863 which is:
var messages = nativeApiProvider.get().exec(service, action, callbackId, argsJson);
I initialize the plugin in the next manner:
FB.init({
appId: Global.Facebook.apiKey,
nativeInterface: CDV.FB,
useCachedDialogs: false,
});
If I remove that permission from scope all works ok. Perhaps anyone has some experience or thoughts on how to fix such issue? I debug my app on my phone (Samsung Galaxy S2 connected via USB debugging feature) and for IDE I use adt-bundle's Android Developer Tools (basicly eclipse);
Many thanks in advance.
I seem to have gotten to the root of the problem. When logging in initially, I can't ask for write ("publish") permissions. As I understand I must ask them later after initial login. Which is abit uncomfortable for me, since I might have to prompt user for permissions several times during a single use-case which is bad. Perhaps I am missing some documentation page where all that stuff is already mentioned?
I've founded !!
Go to FacebookSDK Project -> Properties -> Java Build Path -> Order and Export (tab) -> Make sure android-support-v4.jar is checked. Then do a clean and launch...
Great ?
Use this in your session for publish and read permissions (extended permission.)
session.reauthorizeForPublish

Azure mobile facebook authentication with iPhone HTML5 in app (full screen) mode

I have an HTML5 application that uses Azure mobile services authentication to login (straight from the example code...provided below). It works fine in all desktop browsers and iPhone 5 in Safari. But from app / full screen mode, it does nothing (doesn't ask for permission to show a popup window like it does in safari and no popup windows shows up) and I can wait forever and nothing happens. If I invoke it a second time, it gives an error saying "Error: Unexpected failure"...perhaps because the 1st attempt is still running? Any help/insight is appreciated.
client.login ("facebook").done(function (results) {
alert("You are now logged in as: " + results.userId);
}, function (err) {
alert("Error: " + err);
});
edited update with more info and 2 potential ideas*
I did some more research and found a site that uses an approach that overcomes this problem and also solves two other side effects with the current Azure mobile approach to authentication. I think the Azure mobile team might be looking to do something similar because there are some hints of other authentication options in the code (although difficult to read and be sure because the minimized code is obsfucated). It might be just a matter of activating these in the code...
The "solution":
Go to http://m.bcwars.com/ and click on the Facebook login. You'll see it works perfectly in iPhone Safari in "app mode" becuase instead of doing a popup, it simply stays in the current browser window.
This approach solves two other problems with the current Azure mobile approach. First, the popup gets interpreted by most browsers as a potential ad and is either blocked automatically (desktop Chrome) ... and the user doesn't know why it's not working...or gives a warning which the user has to approve (iPhone Safari in "browser mode") which is a hassle. And if the user has a popup blocker, it gets more difficult and even more potential for the user not getting it to work properly. The bcwars.com method doesn't have this problem.
Second, in iPhone Safari, when the popup window auto closes, the original page doesn't get focus if there are other browser windows open in Safari. Instead, it's in the smaller/slide mode so they can choose which one to show. If this happens, the user has to go through one more sttep...click on the browser window to activate it and give it focus..again more of a pain and more potential for them to mess up and not do it correctly and need help. The m.bcwars.com doesn't have this problem.
Azure options:
Looking at the Azure mobile code it looks like may already have the solution. I can't read it easliy becuase it's minified/obsfucated, but it seems to have 4 options (including iFrame, etc.) for invoking the authentication, and only 1 (the "less ideal one" of a popup) is being used. An easy solution would be to set a property to allow one of the alternate authentications to work. But I can't read it well enough to figure it out. Another would be to hack the code (temporarily until a fix is put up by Microsoft).
Could I get some help there perhaps?
You can implement an authentication flow with Facebook that doesn't use a popup. The basic idea is to use the 'Web Flow' for doing the login, and once the window return from the login, use the access token to login the user in to Azure Mobile Services.
The Facebook documentation for doing this is here:
https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/#step2
Some code samples to make it easier for you.
You would start by something like this:
(Remember to replace YOUR_APP_ID and YOUR_URL with something relevant to your site.
function logIn() {
window.location.replace('https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=http%3A%2F%2FYOUR_URL&response_type=token')
}
This redirects the window to the Facebook page for the user to log in and authorize your app. When the user is done, Facebook will redirect the user back to YOUR_URL given above.
There you can handle the redirect and do the Mobile Services Login with something like this:
function handleLoginResponse() {
var frag = $.deparam.fragment();
if (frag.hasOwnProperty("access_token")) {
client.login("facebook", { access_token: frag.access_token }).then(function () {
// you're logged in
}, function (error) {
alert(error);
});
}
}
In here you parse the access token you get as a URL fragment and pass it as argument to the login call you make to Azure Mobile Services.
This code depends on the jquery BBQ plugin to handle the URL fragment easily.
Hope this solves your problem!