gpt4 book ai didi

android - 在执行 Facebook 发布功能时,某些代码行未执行

转载 作者:行者123 更新时间:2023-11-29 21:43:44 24 4
gpt4 key购买 nike

伙计们,我想在 facebook 上发帖,因为使用 facebook sdk,但有些代码行没有执行。弹出一个登录对话框,当我登录时,SessionEvents.AuthListener listener 应该监听登录成功。但它不听。每次我启动应用程序时,它都会要求登录。
下面是我的代码。

public class FacebookConnector {
private Facebook mFacebook;
private AuthListener mSessionListener;
private Context context;
private String[] permissions;
private Activity activity;

public FacebookConnector(String appId, Activity activity, Context context, String[] permissions) {

this.mFacebook = new Facebook(appId);
SessionStore.restore(mFacebook, context);
SessionEvents.addAuthListener(mSessionListener);
SessionEvents.addLogoutListener((LogoutListener) mSessionListener);
this.context = context;
this.permissions = permissions;
this.activity = activity;

}

public void postMessageOnWall(String msg) {
if (mFacebook.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("message", msg);
try {
String response = mFacebook.request("me/feed", parameters, "POST");
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
} else {
login();
}
}

public void login() {
if (!mFacebook.isSessionValid()) {
mFacebook.authorize(this.activity, this.permissions, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
}

public Facebook getFacebook() {
return mFacebook;
}
}

在我的 Activity 课上....

private void onFacebookBtnClicked() {
if (facebookConnector.getFacebook().isSessionValid()) {
postMessageInThread();
} else {
SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
@Override
public void onAuthSucceed() {
postMessageInThread();
}

@Override
public void onAuthFail(String error) {

}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
}
private void postMessageInThread() {
Thread t = new Thread() {
public void run() {
try {
facebookConnector.postMessageOnWall(mQuote.getQuoteText() + "\n" + mQuote.getAuthorName());
mFacebookHandler.post(mUpdateFacebookNotification);
} catch (Exception ex) {
Log.e("Facebook", "Error sending msg", ex);
}
}
};
t.start();
}

final Runnable mUpdateFacebookNotification = new Runnable() {
public void run() {
Toast.makeText(getBaseContext(), "Facebook updated !", Toast.LENGTH_LONG).show();
}
};

postMessageInThread 方法没有执行,不知道为什么

最佳答案

将此权限设置为公开

private String[] PERMISSIONS = new String[]

{ "publish_stream", "read_stream", "offline_access" };

这将检查 session 是否存在,如果存在则直接更新,如果不存在则请求用户允许在墙上更新。

关于android - 在执行 Facebook 发布功能时,某些代码行未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16392974/

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