1
我正在使用Facebook4j庫將Facebook與我的Android應用程序進行整合。 我在https://github.com/roundrop/facebook4j-android-example的示例後成功登錄,但我沒有找到有關如何註銷的任何文檔或示例。無法使用Facebook4j註銷
有什麼建議嗎?
我正在使用Facebook4j庫將Facebook與我的Android應用程序進行整合。 我在https://github.com/roundrop/facebook4j-android-example的示例後成功登錄,但我沒有找到有關如何註銷的任何文檔或示例。無法使用Facebook4j註銷
有什麼建議嗎?
您可以在下面的代碼只是添加到您的註銷的onclick
fbLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
clearApplicationData();
FBHandler.getInstance(this).facebookLogout();
}
});
,並創建像下面
public class FBHandler {
private static final String TAG = "FBHandler";
private static final String appKey = "Your App Key";
private static Facebook facebook = null;
private static FBHandler _instance = null;
private static Context context = null;
private static String[] permissions = null;
private FBHandler() {
}
public static FBHandler getInstance(Context ctx) {
if (ctx == null) {
Log.d(TAG,
"Error: Context is null, hence returning from the FBHandler");
return null;
}
context = ctx;
if (_instance == null) {
facebook = new Facebook(appKey);
_instance = new FBHandler();
permissions = new String[] { "publish_stream", "user_photos",
"publish_checkins", "email", "publish_actions" };
}
return _instance;
}
public void doPrintoFbUserLogin(final Activity activity,
final fbListner listner) {
if (activity == null || listner == null) {
Log.d(TAG, "Error: User Login activity/Listner is null");
return;
}
facebook.authorize(activity, permissions, new DialogListener() {
public void onComplete(Bundle values) {
printoCommon.showToastMsg(activity,
"facebook Login is succeesfull");
listner.onSuccess();
}
public void onFacebookError(FacebookError e) {
printoCommon.showToastMsg(activity, e.getMessage());
}
public void onError(DialogError e) {
printoCommon.showToastMsg(activity, e.getMessage());
}
public void onCancel() {
printoCommon.showToastMsg(activity,
"Facebook Login is cancelled");
}
});
}
@SuppressWarnings("static-access")
public void uploadUserPhoto(String graphAction, final Activity activity,
Bundle params, uploadListner listner) {
AsyncFacebookRunner fbAsyncRun = new AsyncFacebookRunner(facebook);
params.putString(facebook.TOKEN, facebook.getAccessToken());
fbAsyncRun.request("me/" + graphAction, params, "POST",
new photoUploadListener(activity), null);
}
public void facebookLogout() {
AsyncFacebookRunner fbAsyncRun = new AsyncFacebookRunner(facebook);
fbAsyncRun.logout(context, new AsyncFacebookRunner.RequestListener() {
public void onMalformedURLException(MalformedURLException e,
Object state) {
printoCommon.showToastMsg((Activity) context, e.getMessage());
}
public void onIOException(IOException e, Object state) {
printoCommon.showToastMsg((Activity) context, e.getMessage());
}
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
printoCommon.showToastMsg((Activity) context, e.getMessage());
}
public void onFacebookError(FacebookError e, Object state) {
printoCommon.showToastMsg((Activity) context, e.getMessage());
}
public void onComplete(String response, Object state) {
printoCommon.showToastMsg((Activity) context,
"You have logged out from facebook Successfully");
((Activity) context).finish();
}
});
}
}
很抱歉,您在代碼中使用了Facebook Android SDK,而不是Facebook4j庫! – LucaRoverelli
使用Facebook官方Android SDK中,而不是FBHandler類? –
據我所知,當我發佈新的狀態時,使用官方的SDK詢問確認給用戶,而我需要我的應用程序在沒有任何觸摸交互的情況下發布狀態(用戶將使用聲音命令指定狀態)。 – LucaRoverelli