Android Facebook Graph API 更新状态
我尝试使用 Android 的 Facebook graph API 来更新状态 http://developers .facebook.com/docs/reference/api/status/ 所以,我的问题是您是否可以给我一些示例代码来使用此 API 更新状态。
I've tried to update the status using the Facebook graph API with Android http://developers.facebook.com/docs/reference/api/status/
So, my question is if you can give me some example code to update status using this API.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我使用 Graph API 的完整解决方案
如果您只想更新用户状态,则只需获得“publish_stream”权限。
来自developers.facebook.com...
“publish_stream”:使您的应用能够将内容、评论和点赞发布到用户的流以及用户朋友的流中。拥有此权限后,您可以随时将内容发布到用户的 Feed,无需离线访问。但请注意,Facebook 推荐用户发起的共享模式。
这很重要,因为这意味着您不需要每次尝试更新状态时都重新授权。诀窍是保存密钥/令牌并将其与任何更新请求一起发送。
需要注意的是:我在 Facebook.java 类中将“Facebook.DEFAULT_AUTH_ACTIVITY_CODE”从私有更改为公共。
我的代码有两个按钮,一个用于检查已保存的令牌,另一个仅发送空白令牌,以便我可以测试令牌由于某种原因失败时会发生什么。如果失败,并且 API 返回带有“OAuthException”的字符串,则此代码将重新尝试授权,然后再次尝试更新状态。
FBTest.java
main.xml
Here is my complete solution using the Graph API
If all you intend to do is update the users status you only need to get the "publish_stream" permission.
From developers.facebook.com...
"publish_stream": Enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. With this permission, you can publish content to a user's feed at any time, without requiring offline_access. However, please note that Facebook recommends a user-initiated sharing model.
This is important because it means you do not need to re-authorize every time you attempt to update the status. The trick is to save the key/token and send it with any update request.
One note: I changed "Facebook.DEFAULT_AUTH_ACTIVITY_CODE" from private to public in the Facebook.java class.
My code has two buttons one that checks for a saved token and one that just sends a blank token so I could test what happens if the token fails for some reason. If it does fail, and the API returns a string with "OAuthException" this code makes a new attempt to authorize, then tries to update the status again.
FBTest.java
main.xml
好吧,这可能不是一个完美的代码,但它现在可以工作。您必须修改调用方式和时间以获得更好的用户体验:
这是更新的函数:
我希望它有所帮助。
Okay, This may not be a perfect code, but it works for now. You'll have to modify how and when it is called to get a better user Experience:
This is the function that updates:
I hope it helps.