[英]Android Facebook login without Facebook login button
我想在不使用Facebook登錄按鈕的情況下登錄Facebook。 所以我在默認的android按鈕上應用了click事件。
但我得到錯誤cannot resolve method logInWithReadPermissions(..)..
這是我的代碼。 任何幫助將不勝感激
btnFBLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));// here giving error can not resolve method
}
});
您正在傳遞按鈕的參考
但是你需要傳遞Activity的參考
請使用以下可能對您有幫助的代碼。
LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("public_profile", "email"));
使用
LoginActivity.this // name of the activity and `.this`
而不是this
在按鈕onClick()
函數。 如果您在使用this
在此情況下,它意味着你所指的Button
不活動。 因為這指的是后續父節點,在這種情況下是Button。
如果你在onCreate()
方法中使用相同的代碼(不在任何點擊監聽器等中),那很好因為在這種情況下, this
指的是活動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.