gpt4 book ai didi

android - 来自 Facebook Android 的直接个人资料

转载 作者:太空狗 更新时间:2023-10-29 15:17:34 25 4
gpt4 key购买 nike

我想问一下,如何在成功登录 Facebook 后重定向到某人的个人资料?
示例:如果成功登录并授权,将直接进入此页面:

http://www.facebook.com/torasanshochiku .

我用了this tutorial to connect Facebook

这是我的FacebookConnectionActivity:

public abstract class FBConnectionActivity extends Activity {
public static final String TAG = "FACEBOOK";
private Facebook mFacebook;
public static final String APP_ID = "271496479563642";
private AsyncFacebookRunner mAsyncRunner;
private static final String[] PERMS = new String[] { "read_stream" };
private SharedPreferences sharedPrefs;
private Context mContext;

private TextView username;
private ProgressBar pb;

public void setConnection() {
mContext = this;
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
}

public void getID(TextView txtUserName, ProgressBar progbar) {
username = txtUserName;
pb = progbar;
if (isSession()) {
Log.d(TAG, "sessionValid");
mAsyncRunner.request("me", new IDRequestListener());
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
}

public boolean isSession() {
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String access_token = sharedPrefs.getString("access_token", "x");
Long expires = sharedPrefs.getLong("access_expires", -1);
Log.d(TAG, access_token);

if (access_token != null && expires != -1) {
mFacebook.setAccessToken(access_token);
mFacebook.setAccessExpires(expires);
}
return mFacebook.isSessionValid();
}

private class LoginDialogListener implements DialogListener {

@Override
public void onComplete(Bundle values) {
Log.d(TAG, "LoginONComplete");
String token = mFacebook.getAccessToken();
long token_expires = mFacebook.getAccessExpires();
Log.d(TAG, "AccessToken: " + token);
Log.d(TAG, "AccessExpires: " + token_expires);
sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
sharedPrefs.edit().putLong("access_expires", token_expires)
.commit();
sharedPrefs.edit().putString("access_token", token).commit();
mAsyncRunner.request("me", new IDRequestListener());
}

@Override
public void onFacebookError(FacebookError e) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}

@Override
public void onError(DialogError e) {
Log.d(TAG, "Error: " + e.getMessage());
}

@Override
public void onCancel() {
Log.d(TAG, "OnCancel");
}
}

private class IDRequestListener implements RequestListener {

@Override
public void onComplete(String response, Object state) {
try {
Log.d(TAG, "IDRequestONComplete");
Log.d(TAG, "Response: " + response.toString());
JSONObject json = Util.parseJson(response);

final String id = json.getString("id");
final String name = json.getString("name");
FBConnectionActivity.this.runOnUiThread(new Runnable() {
public void run() {
username.setText("Welcome: " + name+"\n ID: "+id);
pb.setVisibility(ProgressBar.GONE);

}
});
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
} catch (FacebookError e) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}
}

@Override
public void onIOException(IOException e, Object state) {
Log.d(TAG, "IOException: " + e.getMessage());
}

@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
Log.d(TAG, "FileNotFoundException: " + e.getMessage());
}

@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
Log.d(TAG, "MalformedURLException: " + e.getMessage());
}

@Override
public void onFacebookError(FacebookError e, Object state) {
Log.d(TAG, "FacebookError: " + e.getMessage());
}

}

//@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
}

最佳答案

要将用户重定向到某人的个人资料,您可以使用通用个人资料页面链接。
它看起来像这样 -

//facebook.com/profile.php?id=USER_FBID

其中 USER_FBID 是用户的 Facebook ID。因此,您需要做的就是拥有用户 FBID,然后您可以使用链接直接导航到他们的个人资料。请注意,我使用协议(protocol)相对 URL 来使用户在重定向时使用相同的协议(protocol)。如果用户使用 HTTPS 安全浏览,那么他们将被重定向到安全链接。如果用户没有安全浏览,他们将被定向到普通的 HTTP 链接。

关于android - 来自 Facebook Android 的直接个人资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292005/

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