How to find Android application signature in Facebook API using debug logs - android

I have been following the Facebook API guide on https://developers.facebook.com/docs/mobile/android/build/#sig and in step 5 it says
There are two ways to find your Android application signature:
1) From debug logs generated during Single Sign On when there is a signature mismatch.
2) From the Java JDK keytool.
How do I find it using debug logs? I have enabled the logs as they said, using private static boolean ENABLE_LOG = true;. I want to know this because I have tried to get it following step 2, but unsuccessfully. I can't find anything in the logs that would tell me the correct Key Hash.

after setting private static boolean ENABLE_LOG = true;
run single sign on, if at all you dont find the key in error logs then,
add this line of code in one of the callback functions mentioned below
onFacebookError(FacebookError error)
{
System.out.println(error);
}
now run it check error logs, you'll be able to find the key.

Related

Facebook share dialog android return error

I want to share a simple link from my android app.
I followed the getting started guide from Facebook and all seem okay in my app since I can open the share dialog.
I imported FacebookSDK project and linked library
I set my appproperly (package/class name and dev hash keys)
My manifest has right permissions and meta-data
Additional infos :
I use a real device for debug
I run a test app as admin
I'm running a simple share code sample from an activity
I had troubles to generate hash keys but that post helped me. I got an error saying XXX key (different from the one I generated) doesn't match.
Then I tried the method explained here (at the end) to log another key.
Since now, I just get a toast saying "Something went wrong. Please try again."
What am I doing wrong ?
So I solved my problem thanks to another post. The problem is I was trying to generate a key outside my main (first) class.

Android App Signature Key

I want to get the key-hash from signed signature of my Android App so that I can integrate facebook login in my android app. I have created the signed signature using AndroidTools-->Export Signed Application Package. How can I read the key generated in the signature file.
Solution 1:
Try this link: http://www.helloandroid.com/tutorials/using-facebook-sdk-android-development-part-1. I found that using the Facebook method of getting a Hash Key did not always work as advertised. This link however, has a different method of getting the Hash Key and has pretty much always worked.
Solution 2:
That being said, I always found the simplest thing to do was, let the Facebook SDK tell you what your Hash Key is. This is by far more simpler and shouldn't take more than a couple of minutes.
Step 1: In your Facebook SDK, locate the Util.java class. In that, change this:
private static boolean ENABLE_LOG = false;
to:
private static boolean ENABLE_LOG = true;
Step 2: Create a new Signed APK, transfer to your device and install. If it is already installed, naturally, it will prompt.
Step 3: With your DDMS (Logcat) running and your device connected to the computer, run the application and keep looking for a key mismatch warning. That warning has the actual Hash Key. Copy that key, go to your Facebook Developer page and add the new key to the list.

Android Google Plus getCurrentPerson returns null

When I'm calling plusClient.getCurrentPerson() I am getting NULL.
Method onConnected(Bundle...) called after a successful login:
#Override
public void onConnected(Bundle bundle)
{
if (plusClient.getCurrentPerson() == null)
{
Log.e("DD", "Person is null !");
}
}
I have added SHA1 directly from eclipse (Window->Preferences->Android->Build). I don't know what I am doing wrong!
SHA1 fingerprint from Eclipse ADT
Client ID for installed applications
Simple API access
In my case I forgot to enable permission for google-plus
Hope it works...Any doubt let me know
Check from scratch:
Sometime person info may be null
check : PERMISSIONS
Important things to do:
Enable Google plus API
Enable Google Maps Android API
If you test locally then add sha1 key in eclipse-->window-->preference option-->Android-->Build
OR
You can generate SHA1 key through command prompt
keytool -list -v -keystore "C:\Users\User.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
If you are publishing app in play-store then you need to change SHA1 key in google console
because in local SHA1 key is different . After doing signedApk SHA1 key is different
While generating signed apk -->in the last screen -->you can see SHA1 key
After adding in google console you will get API key
Add this key in Manifest file
I just found out that you need to pass multiple scopes when you're building the PlusClient object:
PlusClient plusClient = new PlusClient.Builder(this, this, this).setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE ,"https://www.googleapis.com/auth/userinfo.email").build();
I encountered this today. This is an old post but I think others should know how I fixed this in Android Studio and what was the source of the problem.
I spent the last 6 hours with this and the problem was that a week ago I changed the package name using Refactoring from Android Studio but something must have gotten wrong since would always return me null, even though I refactored the project back to it's original package.
I fixed this by creating a new project, without closing the original, but using the same package name and the same login code from the original project and to my surprise it worked. The name of the new project was different but I named the package the same as the old one and it only had a button and code to manage the connection and nothing else.
The new project would read the data as it should and now the old project somehow got back on his feet and started reading the current user.
I closed the project with Close Project option from the File menu.
Best regards !
Please check your phone network. you can use those codes below to check:
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
#Override
public void onResult(LoadPeopleResult result) {
Log.d(TAG, "result.getStatus():" + result.getStatus());
}
if the result status is network error. the current person will be null.
I'm in China, so as you know if we want to connect the google service , sometimes we need a good agent 。
This looks like a permissions issue. I added payment details in the Google API Console and it magically started working.

Android: Error when login Facebook using new Facebook SDK v3.0.2.b sample

when I using new Facebook SDK v3.0.2.b sample HelloFacebookSample, I login to Facebook but I get error:
HelloFBSample is misconfigured for Facebook login.
But I have already generate Hash key and add it to Sample App Setting on Facebook Developer site.
Is anybody get the same defect?
Or is it a bug of new SDK?
Sometimes the Key Hash generated using the method given by the Facebook Doc does not always work as advertised. I have faced this problem and so have a few others.
There are a couple of things you can do to sort it out.
First method
Follow the tutorial on this site: http://www.helloandroid.com/tutorials/using-facebook-sdk-android-development-part-1
This is a little time consuming (about 5 odd minutes I expect) but worked when I tried it.
Second Method (And I personally like this one)
Find the Util.java in the Facebook SDK and open it.
Among the first few lines of code, you should see this piece: private static boolean ENABLE_LOG = false;.
Change the false to true and run your application with your logcat (DDMD) open.
You should see an error that looks something like this:
Login failed: invalid_key:Android key mismatch. Your key
"**real*key***" does not match the allowed keys specified in
your application settings.
If this is for a testing APK, using the debug.keystore, this will be enough. However, if this is for an app signed with your release key, then follow the steps till Step No. 3 but instead of pushing the app from eclipse, create a signed APK and install that on your device. Don't forget to keep it connected with DDMS running.
This part here: "**real*key***" is your actual key.

Android Facebook API errors with SSO when Facebook App installed

I have been messing with the facebook API/SDK for a while now as I integrate it into an app I am working on. The only real facebook feature I need is checkins, and they work. Most of the time. And here begins my problem.
After looking over the facebook API. I am starting to suspect that either I'm not understanding the API fully, or it is extremely buggy and lacking some important features (like logout?!).
My main problem with these said bugs is that if I have my application checking in to facebook perfectly (on all accounts, not just developer), and then I install the facebook application in order to change users, then the checkin process through my app will not work unless and until I uninstall the facebook application. I have seen several posts about it, but the topic has to my knowledge never been fully discussed here.
I would normally have been more direct with my question, but I fear I may simply be using the api like a moron, and would like to first make sure that this is an actual issue for others besides just me (especially before I commit to the idea that facebook has no idea what they are doing with the API), and second, see if there is any workaround (maybe even the easy facebook library).
Thanks in advance for any advice and/or confirmation of these issues.
EDIT:
So I ended up using the Easy Android facebook Sdk (http://www.easyfacebookandroidsdk.com/). It has poor documentation, but the examples show you enough of what to do that you can mess with it to work.
But my question about how/why facebook can just not include this in their api still stands
This solution worked for me after no other solution did (Cygwin, openssl, wrong alias, wrong password)
The problem is that Windows generates an invalid key.
Run this with your app:
try {
PackageInfo info = getPackageManager().getPackageInfo("**YOURPACKAGENAME**", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("PXR", Base64.encodeBytes(md.digest()));
}
}
catch (NameNotFoundException e) {}
catch (NoSuchAlgorithmException e) {}
Don't forget to get Base64 (http://iharder.sourceforge.net/current/java/base64/).
The generated key is on your logcat, replace the old one with this.
Solution thanks to: http://p-xr.com/implementing-facebook-into-your-app-invalid-key-with-keytool/
If you get invalid_key when the FB app is installed its due to the wrong key you're using.
When running keytool with the debug key such as:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Be sure to enter 'android' as password, and not your keystore password. To verify, make sure the key that you get is not ga0RGNYHvNM5d0SLGQfpQWAPGJ8= but should be something else.
In order to 'logout' try calling SessionStore.clear()
I forgot to update my progress with this. I ended up going with the easy facebook android api because even though it has bugs, it is actively developed, and not a utter useless piece of crap.
For any having the same problems of facebook not fixing their software bugs, check out http://www.easyfacebookandroidsdk.com/
As Guy said, an invalid Key Hash may be the problem. In my case, it turns out that was actually it. Jessy, if that is not your problem, you might want to have a look at the error message generated by the AuthListener.
Before logging in, you probably assign an Authentication listener to the session:
SessionEvents.addAuthListener(new FbAPIsAuthListener());
Now, just go to the function where you implement the listener and try to catch the error:
/*
* The Callback for notifying the application when authorization succeeds or
* fails.
*/
public class FbAPIsAuthListener implements AuthListener {
#Override
public void onAuthSucceed() {
requestUserData();
}
#Override
public void onAuthFail(String error) {
//Could not authenticate. Check error message.
System.out.println("Login error due to " + error)
}
}
Hope that helps.

Categories

Resources