2011-05-26 56 views
2

文件在我的好友列表中选定的朋友,我在做一个样品的Facebook应用程序,因为我必须POST文件到一个特定的朋友不要在我的好友名单公布,不发布在我的墙上,它只能对特定的人可见,我使用下面的代码,它在默认的Facebook Utll类中给出了错误和异常。我在这里发布我的代码,如果改正别人提供一个良好的解决方案成为可能...在此先感谢....POST使用他们的ID

Bundle params = new Bundle(); 
      params=getIntent().getExtras(); 
      String new_data= params.getString("new_frdId"); 
      params.putString("method", "publish_stream"); 
      params.putString("access_token", UI_Friend_Finder.accesstoken); 

      params 
      .putString(
        "attachment", 
        "{\"name\":\"" 
          + "\",\"href\":\"http://www.google.co.in" 
          + "\",\"description\":\" 
          + "\",\"media\":[{\"type\":\"image\",\"src\":\"" 
          + "" 
          + "\",\"href\":\"" 
          + "\"}]}"); 
    authenticatedFacebook.dialog(PostToFriend.this, "stream_publish", 
      params, new TestUiServerListener()); 

         finish(); 
           } 

       }); 
} 
class TestUiServerListener implements DialogListener { 
    public void onComplete(Bundle values) { 
     final String postId = values.getString("post_id"); 
     if (postId != null) { 
      new AsyncFacebookRunner(authenticatedFacebook).request(postId, 
        new TestPostRequestListener()); 
     } else { 
      PostToFriend.this.runOnUiThread(new Runnable() { 
       public void run() { 
       } 
      }); 
     } 
    } 

    public void onCancel() { 
    } 

    public void onError(DialogError e) { 
     e.printStackTrace(); 
    } 

    public void onFacebookError(FacebookError e) { 
     e.printStackTrace(); 
    } 
} 

public class TestPostRequestListener implements RequestListener { 
    public void onComplete(final String response, final Object state) { 
     try { 
      JSONObject json = Util.parseJson(response); 
      String postId = json.getString("id"); 
      PostToFriend.this.runOnUiThread(new Runnable() { 
       public void run() { 
        Log.d("Tests", "Testing wall post success"); 
       } 
      }); 
     } catch (Throwable e) { 
     } 
    } 

    public void onFacebookError(FacebookError e, final Object state) { 
     e.printStackTrace(); 
    } 

    public void onFileNotFoundException(FileNotFoundException e, 
      final Object state) { 
     e.printStackTrace(); 
    } 

    public void onIOException(IOException e, final Object state) { 
     e.printStackTrace(); 
    } 

    public void onMalformedURLException(MalformedURLException e, 
      final Object state) { 
     e.printStackTrace(); 
    } 
} 

public class TestLoginListener implements DialogListener { 
    public void onComplete(Bundle values) { 
     if (authenticatedFacebook.isSessionValid() == true) { 
      String response = null; 
      JSONObject jObject = null; 
      try { 
       jObject = new JSONObject(
         authenticatedFacebook.request("me")); 
      } catch (MalformedURLException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } catch (JSONException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } catch (IOException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } 
      editor.commit(); 

      finish(); 
     } 
    } 

    public void onCancel() { 
    } 

    public void onError(DialogError e) { 
     e.printStackTrace(); 
    } 

    public void onFacebookError(FacebookError e) { 
     e.printStackTrace(); 
    } 
} 

回答

0

这里是code..i把stream.publish方法请求函数内。 。其效果很好..

protected void postToWall(String temp2) { 
    System.out.println("<<inside the post method>>"); 
    Bundle params = new Bundle(); 
    params.putString("message", _messageInput.getText().toString()"some text Here); 
    params.putString("caption", "{*actor*} just posted a secret message."); 
    params.putString("description","A secret message is waiting for you. Click the link to decode it."); 
    params.putString("name", "A Secret Message For You"); 
params.putString("picture","http://www.kxminteractive.com/Content/images/app_logos/secretMessage.png"); 
    params.putString("link", "http://www.kxminteractive.com/decrypt/"); 
    **mAsyncRunner.request(((temp2 == null) ? "me" : temp2) + "/feed", 
       params, "POST", new WallPostRequestListener(),stream.publish);** 
} 
相关问题