2012-09-06 44 views
0

我想發佈照片和消息到用戶的牆上。我的代碼發佈在下面。發佈消息與Android的Facebook中的照片並得到錯誤:發生未知的錯誤

當我發佈消息時,它已成功發佈。但是當我發佈消息與圖片時,我得到一個未知的錯誤。

當用戶按鍵比按下面的代碼會被執行:

 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(); 
    } 
} 

我喜歡未知的錯誤錯誤檢測。我logcat的值是

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) 

10月9日至六日:50:42.251:W/System.err的(352):在dalvik.system.NativeStart.main(本機方法)

+0

請發佈您的整個logcat。 –

+0

你能在這裏複製來自Logcat的消息嗎? –

+0

Tapan Desai和Siddharth Lene我已更新問題logcat值 –

回答

1

使用此行的code:parameters.putString(「access_token」,「」+ st);

試試這可能對你有幫助。


編輯答案

從這裏下載代碼:該代碼clickme

變化APP_ID。

變化如下方法在share_text.java活動

public static void postToWall(String message, Context con) { 

     facebook1 = new Facebook(APP_ID); 
     String st = get_token__(con); 
     Bundle parameters = new Bundle(); 

     parameters.putString("caption", "I Like DJ Call Manager!" + "\n\n" 
       + "https://www.facebook.com/DjCallManager"); 
     parameters.putString("url", 
       "http://www.mspy.com/blog/wp-content/uploads/2012/04/1327425781_1.jpeg"); 

     if (st.length() > 0) { 
      parameters.putString("access_token", "" + st); 
     } 
     try { 

      String response = facebook1 
        .request("me/photos", parameters, "POST"); 
      Log.d("Tests--->*************", "got response: " + response); 

      if (response == null 
        || response.equals("") 
        || response.equals("false") 
        || response 
          .equalsIgnoreCase("{\"error\":{\"message\":\"An active access token must be used to query information about the current user.\",\"type\":\"OAuthException\",\"code\":2500}}")) { 
       showToast("Blank response. please loginf again in facebook", 
         con); 
       clear_fb_data(con); 
      } else { 
       showToast("Message posted to your facebook wall!", con); 
      } 
     } catch (Exception e) { 
      showToast("Failed to post to wall!", con); 
      e.printStackTrace(); 
     } 
    } 

我用URL共享照片只是改變該行共享文件的代碼。

+0

感謝您的回覆,但我仍然有一個錯誤,如09-06 11:56:54.659:D /測試(1271):得到的迴應:{「error」:{ 「message」:「發生未知錯誤。」,「type」:「OAuthException」,「code」:1}} –

+0

嗨,請檢查:http://stackoverflow.com/a/6281905/1168654並添加this String [] PERMISSIONS = new String [] {「publish_stream」};如果您的問題在解決後無法解決,請告訴我您用於登錄Facebook的代碼。 –

+0

雅我的frnd我已經添加了這個權限,但不知道仍然錯誤退出並登錄到Facebook我使用的代碼如authenticatedFacebook.authorize(Tests.this,PERMISSIONS, new TestLoginListener()); –

相關問題