将android应用程序中的图像发布到facebook应用程序墙
我正试图将用户用我的Android应用程序创建的图像发布到Facebook上的应用程序墙上。我已经知道如何在用户的墙上发布图像 我找到了关于如何使用php的教程:将android应用程序中的图像发布到facebook应用程序墙,android,facebook,facebook-wall,Android,Facebook,Facebook Wall,我正试图将用户用我的Android应用程序创建的图像发布到Facebook上的应用程序墙上。我已经知道如何在用户的墙上发布图像 我找到了关于如何使用php的教程: 但我不知道如何获得页面id,也不知道如何使用Android版Facebook sdk 编辑 我在facebook墙上的帖子代码是: public void postImageonWall(String path) { byte[] data = null; Bitmap bi = BitmapFactory.d
但我不知道如何获得页面id,也不知道如何使用Android版Facebook sdk
编辑 我在facebook墙上的帖子代码是:
public void postImageonWall(String path) {
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Facebook facebook = ((MainActivity) appcontext).getFacebook();
Log.d("Facebook-PostImage","facebook: " + facebook);
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putString("message", "Message Text");
params.putString("link","ANDROID_MARKET_LINK"); //or any other link
params.putString("name", "APP/GAME NAME");
params.putByteArray("picture", data);
Log.d("Facebook-PostImage","AsyncRunner going to be called");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new 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());
}
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
// TODO Auto-generated method stub
}
}, null);
}
这是我用于获取我的应用程序页面id的代码:
private JSONObject getJSONfromUrl(String url) throws IOException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
return json;
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
is.close();
}
return null;
}
private String getPageId(String url) {
String identifier = url.substring(url.lastIndexOf("/"));
String graphUrl = "https://graph.facebook.com/" + identifier;
JSONObject response;
String id = null;
try {
response = getJSONfromUrl(graphUrl);
id = (String) response.get("id");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return id;
}
您不确定如何获取页面的页面id?在这里查看几个示例-。一旦你有了页面id,你可以通过-谢谢,我会尝试你的建议。谢谢@deesarus。现在,我可以获得页面id,但我不知道如何在我的代码中使用它。我通过
mAsyncRunner.request更改了我的mAsyncRunner.request(null,params,“POST”,new RequestListener(){…
)请求(pageid+”/feed),params,“POST”,new RequestListener(){…
,但我得到了一个Facebook错误:不支持的方法,photos.upload。