我已经创建了一个应用程序,我希望共享一个图像和一个文本,我已成功获取facebook的登录对话框。但登录后它给了我错误警告:无会话请求需要令牌但丢失应用程序ID或客户端令牌。 我该怎么做才能解决它。我的代码如下,请帮忙......
@SuppressWarnings("deprecation")
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
Session session = facebook.getSession();
if (access_token != null) {
SessionState st = SessionState.OPENED;
facebook.setAccessToken(access_token);
Exception e = new FacebookError("Error");
System.out.println("::::::::::::::aCEESS TOKEN::::::::;;"
+ access_token);
postToWall();
/*fbImageSubmit(facebook, big_img, "3sMAniquines", "Maniquines",
cat_nem, big_img);*/
onSessionStateChange(session, st, e);
Log.d("FB Sessions", "" + facebook.isSessionValid());
}
if (facebook.isSessionValid()) {
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
}
@Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
}
@Override
public void onError(DialogError error) {
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
* */
@SuppressWarnings("deprecation")
public void postToWall() {
// post on user's wall.
facebook.dialog(this, "feed", new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
}
@Override
public void onCancel() {
}
});
}
答案 0 :(得分:0)
您必须保存已登录用户的访问令牌以维护会话以执行进一步的任务。
根据您的代码,以下代码将为您提供当前登录用户的访问令牌。
String access_token = Const.fb.getAccessToken();