Android 保存Facebook个人资料图片和用户名
我一直在为android开发一个简单的应用程序——我正在尝试使用Facebook android SDK使用单点登录登录 我正在尝试保存个人资料图片和用户名。我不太确定到底出了什么问题——但在我登录Facebook之后,似乎什么也没发生 这是我的密码:Android 保存Facebook个人资料图片和用户名,android,facebook,Android,Facebook,我一直在为android开发一个简单的应用程序——我正在尝试使用Facebook android SDK使用单点登录登录 我正在尝试保存个人资料图片和用户名。我不太确定到底出了什么问题——但在我登录Facebook之后,似乎什么也没发生 这是我的密码: public class fbLogin extends Activity { Facebook facebook = new Facebook("MY-APP-ID"); private SharedPreferences mPrefs;
public class fbLogin extends Activity {
Facebook facebook = new Facebook("MY-APP-ID");
private SharedPreferences mPrefs;
public boolean flag=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fblogin_screen);
mPrefs=getPreferences(MODE_PRIVATE);
String acces_token=mPrefs.getString("acces_token",null);
long expires=mPrefs.getLong("acces_expires", 0);
if(acces_token!=null)
{
facebook.setAccessToken(acces_token);
}
if(expires!=0)
{
facebook.setAccessExpires(expires);
}
if(!facebook.isSessionValid())
{
facebook.authorize(this, new DialogListener() {
public void onComplete(Bundle values) {
flag=true;
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
} else{
flag=true;
}
if(flag==true)
{
try {
JSONObject me = new JSONObject(facebook.request("me"));
String id=me.getString("id");
String userName=me.getString("username");
ImageView picture;
TextView usr = (TextView)findViewById(R.id.userName);
picture = (ImageView) findViewById(R.id.profilePicture);
URL image_value= new URL("http://graph.facebook.com/" + userName + "/pictures" );
Bitmap profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
picture.setImageBitmap(profPict);
usr.setText(userName);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
我做错了什么?说:
if(flag==true)
{
try {
JSONObject me = new JSONObject(facebook.request("me"));
String id=me.getString("id");
String userName=me.getString("username");
ImageView picture;
TextView usr = (TextView)findViewById(R.id.userName);
picture = (ImageView) findViewById(R.id.profilePicture);
URL image_value= new URL("http://graph.facebook.com/" + userName + "/pictures" );
Bitmap profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
picture.setImageBitmap(profPict);
usr.setText(userName);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在它自己的方法getInfo()中,然后在您的对话框侦听器中调用getInfo(),如下所示
现在,在FacebookSDK中,有一个名为Utility的类。设置LOGGING=true。
再试试看日志。facebook的日志可能会说你的应用程序哈希和facebook应用程序不匹配。复制日志中的哈希值,转到你的facebook应用程序,选中android应用程序的复选框,并将哈希值粘贴到相应字段中。
if(flag==true)
{
try {
JSONObject me = new JSONObject(facebook.request("me"));
String id=me.getString("id");
String userName=me.getString("username");
ImageView picture;
TextView usr = (TextView)findViewById(R.id.userName);
picture = (ImageView) findViewById(R.id.profilePicture);
URL image_value= new URL("http://graph.facebook.com/" + userName + "/pictures" );
Bitmap profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
picture.setImageBitmap(profPict);
usr.setText(userName);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在它自己的方法getInfo()中,然后在您的对话框侦听器中调用getInfo(),如下所示
现在,在FacebookSDK中,有一个名为Utility的类。设置LOGGING=true。
再试试看日志。facebook的日志可能会说你的应用程序哈希和facebook应用程序不匹配。复制日志中的哈希值,转到facebook应用程序,选中android应用程序的复选框,并将哈希值粘贴到相应字段中。更改此设置
URL图像_值=新URL(“http://graph.facebook.com/“+用户名+”/图片”);
对此
URL图像_值=新URL(“http://graph.facebook.com/“+userName+”/picture”) 改变这个
URL图像_值=新URL(“http://graph.facebook.com/“+用户名+”/图片”);
对此
URL图像_值=新URL(“http://graph.facebook.com/“+userName+”/picture”) 我已经试过了,但还是不行!此外,我的应用程序正在登录facebook,用户名和图片也被检索(我已经检查过了)-唯一的问题是,用户界面在登录后似乎没有更新!我已经试过了,但还是不行!此外,我的应用程序正在登录facebook,用户名和图片也被检索(我已经检查过了)-唯一的问题是,用户界面在登录后似乎没有更新!谢谢,这就是问题所在!谢谢,这就是问题所在!