I'm having problem to picture to wall using facebook sdk. Below is my code.
Facebook permission dialog on start of activity:
fb = new Facebook(fb_id);
fb.authorize(this, new String[] { "publish_stream",
"read_stream", "offline_access","read_friendlists"}, new DialogListener(){
public void onComplete(Bundle values) {
Log.e("oncomplete","value");
if (values.isEmpty()) {
Log.e("oncomplete","value is empty");
return;
}
if (!values.containsKey("POST")) {
token = fb.getAccessToken();
}
}
public void onFacebookError(FacebookError e) {}
public void onError(DialogError e){}
public void onCancel() {}
});
On click of button send feed to wall
public void onClick(View v){
if(v==post_to_wall){
Toast.makeText(getApplicationContext(), "fb token " + token, Toast.LENGTH_LONG).show();
final Handler handler = new Handler(){
public void handleMessage(Message what){
finish();
}
};
Thread thread = new Thread(){
public void run(){
publishToFriendsWall(friends_id);
handler.sendEmptyMessage(0);
}
};
thread.start();
}
}
publish to friends wall method
public void publishToFriendsWall(String friends_id){
if(fb.isSessionValid()){
try{
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, token);
params.putString("message", edittext.getText().toString());
params.putString("link", "http://www.mysite.com");
params.putString("caption", "my caption");
params.putString("description", "description of my link. Click the link to find out more.");
params.putString("name", "my name");
//params.putString("picture", "mypic url");
fb.request(((friends_id == null) ? "me" : friends_id) + "/feed", params, "POST");
}catch(Exception e){
Log.d(null, "Fb post to wall error occured " + e.getClass().getName());
}
}
}
the problem is when i put the following code
params.putString("picture", "mypic url");
there nothing were post to the wall and if i comment the above code it's working fine, I read through the facebook graph api documentation to post a picture it is required access token and valid url for the picture. I've done all that by get access token and the url is valid. what is wrong with my code? There also no error was caught. The only thing i get in logcat is warning like
Key picture expected byte[] but value was a java.lang.String. the default value <null> was return
Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.String
at android.os.Bundle.getByteArray(Bundle.java:1305)
at com.facebook.android.Util.encodePostBody(Util.java:63)
at com.facebook.android.Util.openUrl(Util.java:182)
at com.facebook.android.Facebook.request(Facebook.java:563)