gpt4 book ai didi

android - Facebook 授权访问 token ?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:15:34 27 4
gpt4 key购买 nike

我正在使用教程代码...

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;

public class FacebookSSO extends Activity {

Facebook facebook = new Facebook("ID");

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

facebook.authorize(this,new String[] { "offline_access", "publish_stream", "email" },

new DialogListener() {
@Override
public void onComplete(Bundle values) {}

@Override
public void onFacebookError(FacebookError error) {}

@Override
public void onError(DialogError e) {}

@Override
public void onCancel() {}
});
}

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

facebook.authorizeCallback(requestCode, resultCode, data);
}

我想知道...一旦用户通过身份验证,我将如何存储访问 token ?在教程中看不到任何提及。

最佳答案

facebook.authorize(this,new String[] { "offline_access", "publish_stream", "email" },

new DialogListener() {
@Override
public void onComplete(Bundle values) {}
String token=facebook.getAccessToken(); //get access token
save(token);
@Override
public void onFacebookError(FacebookError error) {}

@Override
public void onError(DialogError e) {}

@Override
public void onCancel() {}
});
}

private void save(String token){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("Token", token).commit();
}

即将其保存在共享首选项中

关于android - Facebook 授权访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5910256/

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