gpt4 book ai didi

android - 如何使用 android 在 Facebook 中授予 publish_action 权限

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:19 25 4
gpt4 key购买 nike

我遇到了错误

java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.

以下是我的代码,

    public class MainActivity extends Activity  {

private static final String TAG = "MainFragment";
private UiLifecycleHelper uiHelper;
WebView webView;
Button nextButton;
LoginButton authButton;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

authButton = (LoginButton) findViewById(R.id.authButton);

authButton.setReadPermissions(Arrays.asList("email","user_birthday","basic_info"));

uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);

}

private void onSessionStateChange(final Session session,
SessionState state, Exception exception) {
if (state.isOpened()) {

// ///////

Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
String access_token = session.getAccessToken();
String email = user.asMap().get("email")
.toString();
Log.i("user",
"user fname====" + user.getFirstName());
Log.i("user",
"user lname======="
+ user.getLastName());
Log.i("user",
"user username====="
+ user.getUsername());
Log.i("user", "user email333======"
+ (String) response.getGraphObject()
.getProperty("email"));
Log.i("user", "user email new222======" + email);
Log.i("user", "user email new111======"
+ user.getProperty("email").toString());
Log.i("user",
"user DOB======" + user.getBirthday());
Log.i("user",
"user getName======" + user.getName());
Log.i("user", "access_token======"

+ access_token);

}


}


});

Request.executeBatchAsync(request);


// /////////
Log.i(TAG, "Logged in...");

authButton.setVisibility(View.VISIBLE);

}

else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}

private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {

System.out.println("statusCallBack Called");
onSessionStateChange(session, state, exception);



}
};

@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {

onSessionStateChange(session, session.getState(), null);
}


uiHelper.onResume();
}

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

uiHelper.onActivityResult(requestCode, resultCode, data);
}


@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}

@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}




}

最佳答案

在您的 Activity 中使用此代码。

authButton.setPublishPermissions("publish_actions", "email",
"user_birthday", "basic_info");

关于android - 如何使用 android 在 Facebook 中授予 publish_action 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21423134/

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