Java 寻找 android Facebook SDK 示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3323496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:09:08  来源:igfitidea点击:

Looking for android Facebook SDK examples

javaandroidfacebooksdkfacebook-android-sdk

提问by brybam

I've looked all over the internet and can't seem to find what i'm looking for...

我已经在互联网上找遍了,似乎找不到我要找的东西......

I'm just trying to find a site with some examples on how to use the OFFICIAL facebook android SDK http://github.com/facebook/facebook-android-sdk

我只是想找到一个网站,里面有一些关于如何使用官方 facebook android SDK http://github.com/facebook/facebook-android-sdk 的例子

To be specific i'd like to see some examples on notification use and simple photo upload. But i'll take anything to help get a feel for using the SDK.

具体来说,我想看一些关于通知使用和简单照片上传的例子。但是我会采取任何措施来帮助您体验使用 SDK。

If anyone knows of any examples please share thank you so much!

如果有人知道任何示例,请分享非常感谢!

采纳答案by RyanM

I asked a similar question a few weeks ago regarding the official Facebook Android SDK and posting content to one's wall (Android/Java -- Post simple text to Facebook wall?). That should help you get a feel for what it's like to post text to one's wall. I should point out though that you need to first create a Fackbook app and apply for an API key from Fackbook.com (https://kunukd.com/)...if it asks about the platform of the app you intent to create, choose mobile.

几周前我问了一个类似的问题,关于官方 Facebook Android SDK 并将内容发布到一个人的墙上(Android/Java - 将简单的文本发布到 Facebook 墙?)。这应该可以帮助您了解将文本张贴到墙上的感觉。我应该指出,您需要先创建一个 Fackbook 应用程序并从 Fackbook.com ( https://kunukd.com/)申请一个 API 密钥……如果它询问您打算创建的应用程序的平台,选择手机。

You can modify the code in the Stack Overflow link I posted (above) to post photos too. At present though, according to the official git page for the Facebook Android SDK (under "Known Issues"):

您也可以修改我发布的 Stack Overflow 链接(上面)中的代码来发布照片。目前,根据 Facebook Android SDK 的官方 git 页面(在“已知问题”下):

3.Binary API parameters (such as uploading pictures) is not yet supported -- coming soon...

3.Binary API 参数(如上传图片)尚不支持——即将推出...

So, while you can post a photo to your wall if you have the URL of the image file (the file must already be on the Internet), you can't use this SDK to send binary/byte data of the photo from the Android device (yet... as of 07/24/10). At least, that's what I gather from the statement above.

因此,虽然如果您有图像文件的 URL(该文件必须已经在 Internet 上),您可以将照片发布到您的墙上,但您不能使用此 SDK 从 Android 发送照片的二进制/字节数据设备(但...截至 10 年 7 月 24 日)。至少,这是我从上面的陈述中收集到的。

Replace the following lines of the sample code I posted in the other Stack Overflow post (link above):

替换我在其他 Stack Overflow 帖子(上面的链接)中发布的示例代码的以下几行:

Bundle parameters = new Bundle();
parameters.putString("message", "this is a test");// the message to post to the wall
facebookClient.dialog(this, "stream.publish", parameters, this);// "stream.publish" is an API call

with this

有了这个

Bundle parameters = new Bundle();
parameters.putString("message", "Test Photo");
parameters.putString("attachment", "{\"name\":\"My Test Image\","
+"\"href\":\""+"http://www.google.com"+"\","
+"\"media\":[{\"type\":\"image\",\"src\":\""+"http://www.google.com/logos/mucha10-hp.jpg"+"\",\"href\":\""+"http://www.google.com"+"\"}]"
+"}");
facebookClient.dialog(this, "stream.publish", parameters, this);

and you should be able to post photos to your wall (as well as text and links).

并且您应该能够将照片发布到您的墙上(以及文本和链接)。

For more help on structuring the "attachment" string, go here: http://www.mobisoftinfotech.com/blog/android/845/.

有关构建“附件”字符串的更多帮助,请访问:http: //www.mobisoftinfotech.com/blog/android/845/

Other than that, consider using a third-party package or wait for the official SDK to be updated if you need to post photos to an album directly from the device.

除此之外,如果您需要直接从设备将照片发布到相册,请考虑使用第三方包或等待官方SDK更新。

回答by plug-in

You can do it this way:

你可以这样做:

byte[] data = null;
try {
    ContentResolver cr = mainActivity.getContentResolver();
    InputStream fis = cr.openInputStream(localSnapshotUri);
    Bitmap bi = BitmapFactory.decodeStream(fis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();              
} catch (FileNotFoundException e) {
    e.printStackTrace();
}     

Bundle params = new Bundle(); 
params.putString("method", "photos.upload");          
params.putByteArray("picture", data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener());

Parameters used here are:

这里用到的参数是:

  • localSnapshotUriwhich points to some image in you /sdcard/.. or wherever it is :)
  • mainActivitythat is app main activity
  • SampleUploadListeneran implemetation of AsyncFacebookRunner.RequestListenerinterface
  • localSnapshotUri它指向你 /sdcard/.. 或任何地方的一些图像:)
  • mainActivity那是应用程序的主要活动
  • SampleUploadListenerAsyncFacebookRunner.RequestListener接口的实现

Have a nice programming!

祝你编程愉快!

回答by trgraglia

Just posted here the simple way to upload a photo:

刚刚在这里发布了上传照片的简单方法:

android facebook publish photo

android facebook 发布照片

Code:

代码:

byte[] data = null;

Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();

Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);

回答by Yar

By far the easiest and working example of posting to user's wall without the dialog once logged on, and using the new Facebook SDK, is: http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/

到目前为止,在登录后无需对话框并使用新的 Facebook SDK 发布到用户墙的最简单且有效的示例是:http: //www.integratingstuff.com/2010/10/14/integrating-facebook-into-一个安卓应用程序/

By the way, posting images is done with:

顺便说一下,发布图像是通过以下方式完成的:

parameters.putString("picture", "http://www.google.com/logos/mucha10-hp.jpg");