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