我已经被困了好几天找上制作一个Facebook的墙后带图标或图像,并使用图形API的一些文本的简单教程。我试过无数的教程,他们都显得很复杂,我不能让他们的工作。即使是附带SDK中的样本不创建会话。
I've been stuck for days looking for a simple tutorial on making a facebook wall post with an icon or image and some text using the graph API. I've tried countless tutorials and they all seem very complicated and I can't get them to work. Even the samples that come with the SDK do not create sessions.
我一直SUCESSFUL设立的SDK,并让我的APP_ID所有剩下的是Java code为自定义按钮分享我的用户墙上的应用程序。
I have been sucessful in setting up the SDK and getting my APP_ID all that is left is the Java code for a custom button to share my app on the users wall.
您可以在一个非常简单的方式发布的文字图像从你的应用程序。
you can post your image with text from your application in a very simply way.
调用此方法同时点击按钮控件说 btnImagePostToWall
像...
Call this method while clicking on the button widget say btnImagePostToWall
like...
btnImagePostToWall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postImageToWall();
}
});
通过要求Facebook的图形API获取资料信息......
Get Profile information by making request to Facebook Graph API....
public void postImageToWall() {
facebook.authorize(
this,
new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" },
new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
@Override
public void onError(DialogError dialogError) {
// TODO Auto-generated method stub
}
@Override
public void onComplete(Bundle values) {
postImageonWall();
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
});
}
private void postImageonWall() {
byte[] data = null;
Bitmap bi = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data); // image to post
params.putString("caption", "My text on wall with Image "); // text to post
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(),
null);
}
只要创建一个类SampleUploadListener它实现AsyncFacebookRunner.RequestListener ...
Just create a class SampleUploadListener which implements AsyncFacebookRunner.RequestListener...
class SampleUploadListener implements AsyncFacebookRunner.RequestListener {
@Override
public void onComplete(String response, Object state) {
}
@Override
public void onIOException(IOException e, Object state) {
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
@Override
public void onFacebookError(FacebookError e, Object state) {
}
}
希望这会帮助你有点....: - )
Hope this will help you a bit.... :-)