gpt4 book ai didi

android - Facebook Android sdk 3.0 授权对话框未显示请求的权限

转载 作者:太空狗 更新时间:2023-10-29 12:48:55 26 4
gpt4 key购买 nike

我要的是电子邮件、user_birthday 和姓名。每次出现登录 Web View 时,它只列出基本信息。

好像和onClickLogin监听中调用openActiveSession有关系

此类是“SessionLoginSample”facebook 示例项目的“LoginUsingActivityActivity.java”文件的复制/粘贴。我添加的唯一内容是权限、关闭 session onStart 和 onStop,以及在 SessionStatusCallback 中添加检索用户信息的请求。

我无法找到授权对话框中未显示权限的原因。非常感谢任何帮助,代码粘贴在下面。

package com.mydomain.test.login;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.LoggingBehavior;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.Settings;
import com.facebook.model.GraphUser;

public class LoginTest extends Activity {
private static final String URL_PREFIX_FRIENDS = "https://graph.facebook.com/me/friends?access_token=";
private List<String> perms;

private TextView textInstructionsOrLink;
private Button buttonLoginLogout;
private Session.StatusCallback statusCallback = new SessionStatusCallback();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_test);
buttonLoginLogout = (Button)findViewById(R.id.fbLogin);
textInstructionsOrLink = (TextView)findViewById(R.id.textView1);
perms = new ArrayList<String>();
perms.add("email");
perms.add("name");
perms.add("user_birthday");

Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(perms));
}
}

updateView();
}

@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
if( Session.getActiveSession() != null )
Session.getActiveSession().close();
}

@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
if( Session.getActiveSession() != null )
Session.getActiveSession().close();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}

private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
textInstructionsOrLink.setText(URL_PREFIX_FRIENDS + session.getAccessToken());
buttonLoginLogout.setText(R.string.fbLogout);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
public void onClick(View view) { onClickLogout(); }
});
} else {
textInstructionsOrLink.setText(R.string.hello_world);
buttonLoginLogout.setText(R.string.fbLogin);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
public void onClick(View view) { onClickLogin(); }
});
}
}

private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(perms));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}

private void onClickLogout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}

private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
if( session.isOpened() ){
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

@Override
public void onCompleted(GraphUser user, Response response) {
Log.i("FB_TEST", response.toString());
Log.i("FB_TEST", user.getName() + " -- " + "DOB: " + user.getBirthday() + " EMAIL: " + user.getProperty("email"));
}
});
}
updateView();
}
}
}

最佳答案

您可以使用以下代码添加所需的权限

  session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(Arrays.asList("email", "user_status")));

关于android - Facebook Android sdk 3.0 授权对话框未显示请求的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14695599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com