2012-07-17 71 views
0

我想使用android facebook sdk標記wallpost中的朋友。但是,標籤應該是什麼,是空白的,什麼都不是。這是我所使用的代碼:使用Android Facebook sdk標記wallpost中的朋友sdk

  Bundle params = new Bundle(); 
      access_token = fb.getAccessToken(); 

      try { 
       params.putString("format", "json"); 
       params.putString("access_token", access_token); 
       String url = "https://graphs.facebook.com/me/friends"; 
       String response = Util.openUrl(url, "GET", params); 
       JSONObject json = Util.parseJson(response); 
       JSONArray array = json.optJSONArray("data"); 

       for(int i = 0; i < array.length(); i++) { 
        String tempName = array.getJSONObject(i).getString("name"); 
        String tempID = array.getJSONObject(i).getString("id"); 

        //Probably should have some if-tests here 

        if(tempName.contains(*nameOfFriend*)) { 
         Bundle bundle = new Bundle(); 
         bundle.putString("message", "App tagging test"); 
         //this is where the tagging is supposed to happen 
         bundle.putString("tags", *UserID*); 
         try { 
          fb.request("me/feed", bundle, "POST"); 
          Toast.makeText(getApplicationContext(), "Tag-test", Toast.LENGTH_SHORT).show(); 
         } catch (MalformedURLException e) { 
          Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show(); 
          e.printStackTrace(); 
         } catch (IOException e) { 
          Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show(); 
          e.printStackTrace(); 
         } 
        } else { 
         Toast.makeText(getApplicationContext(), "Couldn't find friend", Toast.LENGTH_SHORT).show(); 
        } 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 

我只授予「publish_stream」許可,會不會是我需要的其他權限? 在此先感謝您的幫助!

+0

等離子請提供您的問題的解決方案 – jyomin 2014-10-30 05:34:04

+0

@jyomin不幸的是,我從來沒有找到解決方案。此外,我的問題中的代碼現在已過時,因爲它是舊的Facebook SDK。 – Plasma 2014-10-30 10:46:07

+0

好的沒問題,謝謝回覆。 – jyomin 2014-10-31 05:02:58

回答

2

以下是工作的代碼也標記朋友 你必須提交您的評論到fb爲您在devlepoer Facebook的創建項目的加標籤友API功能account.After你得到批准提交的信息以下代碼會標記你的朋友。

 Bundle params = new Bundle(); 
    params.putString(Facebook.TOKEN, facebook.getAccessToken()); 
    params.putString("method", "photos.upload"); 
    params.putString("caption", ShareTripActivity.tripNotes); // text to post 

    if(ShareTripActivity.arr_facebookID.size()>0) 
    { 
     String tagFriendListId=""; 
     for(int i=0;i<ShareTripActivity.arr_facebookID.size();i++) 
     { 

      tagFriendListId = tagFriendListId+"{'tag_uid':'"+ShareTripActivity.arr_facebookID.get(i)+"'} ,"; 

     } 
     tagFriendListId=tagFriendListId.substring(0, tagFriendListId.length()-1); 
     params.putString("tags","["+tagFriendListId+"]"); 

    } 
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook); 
    mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); 

//樣本上傳聽衆

公共類SampleUploadListener擴展BaseKeyListener實現RequestListener {

public void onComplete(final String response, final Object state) 
    { 
     try 
     { 
      // process the response here: (executed in background thread) 
      Log.d("Facebook-Example", "Response: " + response.toString()); 
      JSONObject json = Util.parseJson(response); 
      final String src = json.getString("src"); 

      // 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 in response"); 
     } 
     catch (FacebookError e) 
     { 
      Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
     } 
    } 

    public void onFacebookError(FacebookError e, Object state) 
    { 
     // TODO Auto-generated method stub 

    } 

    public Bitmap getInputType(Bitmap img) 
    { 
     // TODO Auto-generated method stub 
     return img; 
    } 

    public int getInputType() 
    { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    public void onIOException(IOException e, Object state) 
    { 
     // TODO Auto-generated method stub 

    } 

    public void onFileNotFoundException(FileNotFoundException e, Object state) 
    { 
     // TODO Auto-generated method stub 

    } 

    public void onMalformedURLException(MalformedURLException e, Object state) 
    { 
     // TODO Auto-generated method stub 

    } 
} 

在這種arr_facebookID是包含了你的朋友的facebook_user_id就是你所要標記的數組列表。

+0

謝謝!我現在不使用Facebook或Android,所以我無法驗證它是否有效。但是出色的工作,我會將其標記爲已接受。 – Plasma 2014-11-15 11:16:57

0

我在代碼中看不到place的任何值,但在爲通過API製作的帖子中標記人物時,需要需要

https://developers.facebook.com/docs/reference/api/user/#posts

標籤[...]注意:如果不同時指定一個地方你不能指定此字段。

+1

非常感謝您的快速回復!從應用標記時使用地點的風俗有哪些?我是否必須創建一個地方進行登記(即創建一個地方並將其稱爲與應用程序本身相同),還是應該用高度和長度來檢索物理位置?還是我完全誤解了?你有代碼示例嗎?再次感謝您的回覆! – Plasma 2012-07-17 15:19:43

相關問題