gpt4 book ai didi

android - 只能通过一个帐户登录,不能使用另一个ID登录Facebook

转载 作者:行者123 更新时间:2023-11-30 02:56:52 26 4
gpt4 key购买 nike

在我的应用程序中,我可以通过我的 facebook id 登录。我输入另一个 id,它没有像我的 id 那样获取数据。我不明白这是什么问题。当我输入另一个 id 时,它显示正在加载,之后只能看到空白的 Facebook 页面。

主 Activity

public class MainActivity extends Activity {
Facebook fb;
Button login,getData,logout;
ImageView ig;
String app_id;
private AsyncFacebookRunner mAsyncRunner;

private SharedPreferences mPrefs;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
app_id= getString(R.string.app_id);
fb= new Facebook(app_id);
login=(Button) findViewById(R.id.login);
logout=(Button) findViewById(R.id.logout);
getData=(Button) findViewById(R.id.getData);
// ig= (ImageView) findViewById(R.id.profile_pic);
login.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
loginToFacebook();
}
});

getData.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
getProfileInformation();
}
});
logout.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(fb.isSessionValid()){
logoutFromFacebook();
}

}
});
mAsyncRunner = new AsyncFacebookRunner(fb);
//updateButtonImage();
try {

PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);

for (Signature signature : info.signatures)
{
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}

} catch (NameNotFoundException e) {
Log.e("name not found", e.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
}
}




@SuppressWarnings("deprecation")
public void loginToFacebook() {

mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);

if (access_token != null) {
fb.setAccessToken(access_token);

login.setVisibility(View.VISIBLE);

// Making get profile button visible
getData.setVisibility(View.VISIBLE);

Log.d("FB Sessions", "" + fb.isSessionValid());
}

if (expires != 0) {
fb.setAccessExpires(expires);
Toast.makeText(getApplication(), "already login", Toast.LENGTH_LONG).show();
//logoutFromFacebook();
}

if (!fb.isSessionValid()) {
fb.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
editor = mPrefs.edit();
editor.putString("access_token",
fb.getAccessToken());
editor.putLong("access_expires",
fb.getAccessExpires());
editor.commit();

// Making Login button invisible
login.setVisibility(View.VISIBLE);

// Making logout Button visible
getData.setVisibility(View.VISIBLE);


}

@Override
public void onError(DialogError error) {
// Function to handle error

}

@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors

}

});
}
}

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


@SuppressWarnings("deprecation")
public void getProfileInformation() {
mAsyncRunner.request("me", new RequestListener() {
public void onComplete(String response, Object state) {
Log.d("Profile", response);
String json = response;
try {
// Facebook Profile JSON data
JSONObject profile = new JSONObject(json);

// getting name of the user
final String name = profile.getString("name");

// getting email of the user
final String email = profile.getString("email");

runOnUiThread(new Runnable() {

@Override
public void run() {
Toast.makeText(getApplicationContext(), "Name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show();

}

});


} catch (JSONException e) {
e.printStackTrace();
}
}

public void onIOException(IOException e, Object state) {
}

public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}

public void onMalformedURLException(MalformedURLException e,
Object state) {
}

public void onFacebookError(FacebookError e, Object state) {
}
});

}

最佳答案

我遇到了同样的问题。我是这样修好的。

前往 Facebook 开发者页面

Apps --> "YourApp"--> Status and Review --> Enable(“你想让这个应用程序及其所有实时功能对公众开放吗?”)

像这样

enter image description here

关于android - 只能通过一个帐户登录,不能使用另一个ID登录Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124623/

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