gpt4 book ai didi

android - 登录后在另一个 Activity 中获取 Facebook 个人资料

转载 作者:行者123 更新时间:2023-11-30 02:46:50 24 4
gpt4 key购买 nike

大家好,我在 youtube 上发现了有趣的 Facebook 实现方法,虽然有些方法已被弃用,但我发现它很容易使用,因为我是我的 Android 应用程序中 Facebook 实现的新手。我遇到了一些问题,我通过登录 Activity 成功登录到 Facebook,但在那里他们在同一 Activity 中显示用户个人资料,在我的情况下,我不想在我保存用户的另一个 Activity 中显示他们共享首选项中的凭据和 session 有效但是在实现用户配置文件的解析内容时我什么也没得到不知道为什么这是我的代码。

在此输入验证码

private void updateView() 
{
// TODO Auto-generated method stub
if(fb.isSessionValid())
{
Intent openActivity=new Intent(FacebookLoginActivity.this,AccountInfoActivity.class);
startActivity(openActivity);
}
}

这里的 session 有效,所以我可以进行下一个 Activity

在此输入验证码

 public class AccountInfoActivity extends Activity
{
Facebook fb;
String id,name,email;
Bitmap bmp;
ImageView profile_pic;
TextView facebook_name,facebook_email;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_profile);

String APP_ID= "**************";
fb= new Facebook(APP_ID);

profile_pic=(ImageView)findViewById(R.id.profile_pic);
facebook_name=(TextView)findViewById(R.id.facebookName);
facebook_email=(TextView)findViewById(R.id.facebookEmail);

(new DataProgressTask()).execute();

}
public class DataProgressTask extends AsyncTask<String, Void, Boolean>
{
ProgressDialog progress;

public DataProgressTask()
{
progress = new ProgressDialog(AccountInfoActivity.this);
}
protected void onPreExecute()
{
progress.setMessage("Loading data ...");
progress.show();
}
@Override
protected void onCancelled()
{
if ( progress != null )
{
progress.dismiss();
}
}

protected void onPostExecute(final Boolean success)
{
//Check if dialog still runing dismiss
if ( progress != null)
{
progress.dismiss();
}

if (success)
{
facebook_name.setText(name);
facebook_email.setText(email);
profile_pic.setImageBitmap(bmp);
}
else
{
Toast.makeText(getBaseContext(), "Check your Internet Connection", Toast.LENGTH_SHORT).show();
}


}
@SuppressWarnings("deprecation")
protected Boolean doInBackground(final String... args)
{
if(fb.isSessionValid())
{

JSONObject obj= null;
URL img_url = null;

String jsonUser;

try
{


jsonUser = fb.request("me");
obj = Util.parseJson(jsonUser);

id = obj.optString("id");
name= obj.optString("name");
email= obj.optString("email");
//getting the image of the user
img_url = new URL("http://graph.facebook.com/"+id+"/picture?type=small");
//decode it to bitmap
bmp =BitmapFactory.decodeStream(img_url.openConnection().getInputStream());
profile_pic.setImageBitmap(bmp);

}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (FacebookError e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}

}}

如有任何帮助,我们将不胜感激。谢谢

最佳答案

我设法通过将用户配置文件的数据从登录 Activity 发送到其他 Activity 来解决我的问题,如果 session 有效,则所有这些都已完成:D

关于android - 登录后在另一个 Activity 中获取 Facebook 个人资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875781/

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