I am trying to post a photo and a message to a user's wall. My code is posted below.
When I post just the message, it is successfully posted. But when I post message with a picture I get an Unknown error.
When user press on Button than below code will be execute:
mFacebook.authorize(MainActivity.this, new String[] { "user_about_me", "email","publish_stream", "read_stream", "offline_access" }, new TestLoginListener());
public class TestLoginListener implements DialogListener {
public void onComplete(Bundle values) {
try {
{
Bundle parameters = new Bundle();
parameters.putString("message", "Test\n");
String path=Environment.getExternalStorageDirectory()+"/Diegodeals/";
if(!new File(path).exists()) new File(path).mkdirs();
File photo = new File(path, "diegodeals.jpg");
if(photo!=null){
System.out.println(Uri.fromFile(photo).toString());
parameters.putString("picture", Uri.fromFile(photo).toString());
}
String response = mFacebook.request("me/feed", parameters, "POST");
JSONObject json;
try
{
json = Util.parseJson(response);
if (!json.isNull("id"))
{
Toast.makeText(MainActivity.this, "SUCCESSED ssssssss", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.this, "fail", Toast.LENGTH_LONG).show();
}
} catch (FacebookError e)
{
e.printStackTrace();
}
new FBLongOpertaion().execute("");
}
/*String resID = mFacebook.request("me");
JSONObject objId = Util.parseJson(response);*/
} catch (Exception e) {
e.printStackTrace();
}
}
public void onCancel() {
}
public void onError(DialogError e) {
e.printStackTrace();
}
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
}
I got an error like UnKnown Error Detected. My Logcat value is
09-06 10:50:42.210: W/System.err(352): com.facebook.android.FacebookError: An unknown error has occurred.
09-06 10:50:42.240: W/System.err(352): at com.facebook.android.Util.parseJson(Util.java:279)
09-06 10:50:42.240: W/System.err(352): at com.eheuristics.android.diegodeals.MainActivity$TestLoginListener.onComplete(MainActivity.java:146)
09-06 10:50:42.240: W/System.err(352): at com.facebook.android.Facebook$1.onComplete(Facebook.java:354)
09-06 10:50:42.240: W/System.err(352): at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:145)
09-06 10:50:42.240: W/System.err(352): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:216)
9-06 10:50:42.240: W/System.err(352): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:323)
09-06 10:50:42.240: W/System.err(352): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 10:50:42.240: W/System.err(352): at android.os.Looper.loop(Looper.java:130)
09-06 10:50:42.240: W/System.err(352): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-06 10:50:42.251: W/System.err(352): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 10:50:42.251: W/System.err(352): at java.lang.reflect.Method.invoke(Method.java:507)
09-06 10:50:42.251: W/System.err(352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-06 10:50:42.251: W/System.err(352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-06 10:50:42.251: W/System.err(352): at dalvik.system.NativeStart.main(Native Method)
Use this line in your code : parameters.putString("access_token", "" + st);
try this it may help you.
edited answer
download code from here : clickme
change APP_ID in that code.
change below method in share_text.java Activity
i used URL to share photo just change that line to share file code.