How to retrieve an Facebook-AuthToken from the accounts saved on Android

我只是一个虾纸丫 提交于 2019-11-28 10:17:56

Why not use the Facebook SDK?

The Facebook class in it has a member to get the OAuth 2.0 access token (if that is what you need), getAccessToken().

To explain the fact that neither of your logging statements are being reached, consider:

Line ~8:

        am.getAuthToken(account, "com.facebook.auth.login", null, ConversationList.this,

... can return a token if it's immediately available. Maybe that's the answer you're looking for? Quoting the AccountManager documentation:

If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, the user is prompted to enter a password.

Try calling AccountManager.blockingGetAuthToken instead. If that works, then there's something more interesting at fault here...

Also, make sure your manifest has the USE_CREDENTIALS permission set correctly.

add try { before am.getAuthToken and catch Exception where this method declaration ends.This will give you why and where excepption is happening

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!