(对不起我的英语)。我正在尝试将使用我的应用程序拍摄的照片发布给用户 Wall,我已经成功但我无法在帖子上标记一些朋友,图像已上传并且位置标记正确,但是朋友没有被标记。
我在 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。
如果任何人都可以帮助我弄清楚为什么没有标记朋友或者做相同帖子的新方法是什么,我将非常感激