使用Facebook登录Android应用程序:活动的访问令牌必须被用于查询当前用户信息 [英] Android app using Facebook login: An active access token must be used to query information about the current user
本文介绍了使用Facebook登录Android应用程序:活动的访问令牌必须被用于查询当前用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经整合Facebook登录我的应用程序,而是试图让这个名字在对登录用户的基本信息的时候,我得到:
{
响应:响应code:400,
graphObject:空,
错误: {
的HTTPStatus:400,
错误code:2500,
ERRORTYPE:OAuthException,
的errorMessage:活性访问令牌必须用于查询当前用户的信息。
},
isFromCache:假的
}
我登录我的会话令牌和到期日期,这是不为空,也没有过期。我试着用的getActiveSession(更换会议),但并没有解决任何事情。
私人无效onSessionStateChange(会话的会话,SessionState会状态,例外的例外){
如果(state.isOpened()){
最终的共享preferences preFS = getActivity()。getShared preferences(
fbInfo,Context.MODE_PRIVATE);
如果(会话= NULL和放大器;!&安培; session.getState()isOpened()){
Log.i(sessionToken,session.getAccessToken());
Log.i(sessionTokenDueDate,session.getExpirationDate()的toLocaleString());
}
新的请求(会话,/我?域=名称,空,HttpMethod.GET,
新Request.Callback(){
公共无效onCompleted(响应响应){
JSONObject的graphResponse =响应
.getGraphObject()
.getInnerJSONObject();
尝试 {
。prefs.edit()putString(名,graphResponse.getString(名字))提交();
}赶上(JSONException E){
Log.i(TAG,
JSON错误+ e.getMessage());
}
}
}
).executeAsync();
新的请求(会话,/我?域=引号,空,HttpMethod.GET,
新Request.Callback(){
公共无效onCompleted(响应响应){
JSONObject的graphResponse =响应
.getGraphObject()
.getInnerJSONObject();
尝试 {
。prefs.edit()putString(报价,graphResponse.getString(报价))提交();
}赶上(JSONException E){
Log.i(TAG,
JSON错误+ e.getMessage());
}
}
}
).executeAsync();}
解决方案
试试这个
如果(state.isOpened())
{
Log.i(脸谱,已登录......);
新的请求(会话,我/照片,getRequestParameters(),null,则新的回调()
{
@覆盖
公共无效onCompleted(响应响应)
{
}
})executeAsync()。
....
私人捆绑getRequestParameters()
{
捆绑参数=新软件包(1);
parameters.putString(域,图像,其他);
返回参数;
}
I have integrated Facebook login in my app, but when trying to get the name out of the basic info of the logged in user, I get:
{
Response: responseCode: 400,
graphObject: null,
error: {
HttpStatus: 400,
errorCode: 2500,
errorType: OAuthException,
errorMessage: An active access token must be used to query information about the current user.
},
isFromCache:false
}
I logged my session token and its expiration date and it is not null nor expired. I tried replacing session with getActiveSession() but that didn't fix anything.
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
final SharedPreferences prefs = getActivity().getSharedPreferences(
"fbInfo", Context.MODE_PRIVATE);
if (session != null && session.getState().isOpened()){
Log.i("sessionToken", session.getAccessToken());
Log.i("sessionTokenDueDate", session.getExpirationDate().toLocaleString());
}
new Request(session, "/me?fields=name", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
try {
prefs.edit().putString("name", graphResponse.getString("name")).commit();
} catch (JSONException e) {
Log.i(TAG,
"JSON error " + e.getMessage());
}
}
}
).executeAsync();
new Request(session, "/me?fields=quotes", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
try {
prefs.edit().putString("quotes", graphResponse.getString("quotes")).commit();
} catch (JSONException e) {
Log.i(TAG,
"JSON error " + e.getMessage());
}
}
}
).executeAsync();}
解决方案
Try this
if (state.isOpened())
{
Log.i("Facebook", "Logged in...");
new Request(session, "me/photos",getRequestParameters(), null, new Callback()
{
@Override
public void onCompleted(Response response)
{
}
}).executeAsync();
....
private Bundle getRequestParameters()
{
Bundle parameters = new Bundle(1);
parameters.putString("fields", "images,other");
return parameters;
}
这篇关于使用Facebook登录Android应用程序:活动的访问令牌必须被用于查询当前用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文