2012-11-02 125 views
1

(對不起,我的英文)。我試圖將我的應用拍攝的照片貼到用戶牆上,而且我成功了,但是我不能在帖子上標記一些朋友,圖片上傳並且地點標記正確,但朋友沒有被標記。
我曾在Facebook上搜索文檔和示例,但我只找到如何發佈照片上傳到服務器,而不是如何將其上傳到Facebook。標記朋友上傳照片到臉書

我用這個代碼:

/** 
* Posts an image on Facebook user wall. 
* @param path path of the image to be posted. 
* @param act activity caller. 
* @param text description of the photo. 
*/ 
public void postImageOnWall(final Activity act, final String path, 
     final String text) { 
    if (facebook.isSessionValid()) { 
     byte[] data = null; 

     Bitmap bi = BitmapFactory.decodeFile(path); 
     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     bi.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
     data = baos.toByteArray(); 

     StringBuilder str = new StringBuilder(); 
     str.append(text); 
     str.append("\n" + act.getResources().getString(
       R.string.facebook_signature_android)); 
     str.append("\n" + act.getResources().getString(
       R.string.facebook_signature_ios)); 

     Bundle params = new Bundle(); 
     params.putString(Facebook.TOKEN, facebook.getAccessToken()); 
     params.putString("link", "www.example.com"); 
     params.putString("place", "--placeId--"); 
     params.putStringArray("to", new String[]{"--friendId1--","--friendId2--"}); 
     params.putStringArray("tags", new String[]{{"--friendId1--","--friendId2--"}); 
     params.putString("name", str.toString()); 
     params.putByteArray("picture", data); 

     AsyncFacebookRunner mAsyncRunner = 
       new AsyncFacebookRunner(facebook); 
     mAsyncRunner.request("me/photos", params, "POST", 
       new RequestListener() { 
      public void onComplete(
        final String response, final Object state) { 
        try { 
         // process the response here: 
         Log.i("Facebook-Example", 
           "Response: " + response.toString()); 
         JSONObject json = Util.parseJson(response); 
         String id = json.getString("id"); 


         // then post the processed result back to the UI thread 
         // if we do not do this, an runtime exception will be generated 
         // e.g. "CalledFromWrongThreadException: Only the original 
         // thread that created a view hierarchy can touch its views." 

        } catch (JSONException e) { 
         Log.w("Facebook-Example", 
           "JSON Error: " + e.getMessage()); 
        } catch (FacebookError e) { 
         Log.w("Facebook-Example", 
           "Facebook Error: " + e.getMessage()); 
        } 
       } 
      @Override 
      public void onIOException(final IOException e, 
        final Object state) { 
       Log.e("Facebook-Request", "Facebook IOException: " 
         + e.getMessage()); 
       e.printStackTrace(); 
      } 
      @Override 
      public void onFileNotFoundException(
        final FileNotFoundException e, 
        final Object state) { 
       Log.e("Facebook-Request", "Facebook FileNotFoundException: " 
         + e.getMessage()); 
       e.printStackTrace(); 
      } 
      @Override 
      public void onMalformedURLException(
        final MalformedURLException e, 
        final Object state) { 
       Log.e("Facebook-Request", "Facebook MalformedURLException: " 
         + e.getMessage()); 
       e.printStackTrace(); 
      } 

      @Override 
      public void onFacebookError(final FacebookError e, 
        final Object state) { 
       Log.e("Facebook-Request", "Facebook FacebookError: " 
         + e.getMessage()); 
       e.printStackTrace(); 
      } 
       }, null); 
    } else { 
     Toast.makeText(act, "Not connected to Facebook", 
       Toast.LENGTH_LONG).show(); 
    } 
} 

昨天我下載了Facebook SDK 3現在mAsyncRunner.request()方法已被棄用,我想不出如何與新的SDK做到這一點。

如果任何人都可以幫助我弄清楚爲什麼朋友沒有被標註或什麼是做同樣的職位,我會非常感激的新方法

回答

0

這個例子顯示,你張貼的東西到新的方法使用我們新的SDK用戶的牆:

https://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/#step2

讓我知道是否有幫助。

+0

非常感謝,您的鏈接只介紹如何發佈一個飼料鏈接上傳到服務器的圖像。我需要從手機上傳圖片。 – goda87

+0

我設法編輯鏈接上的代碼來做同樣的事情,我正在做,謝謝!現在我的代碼不被棄用,但我仍然無法標記任何人。 – goda87