在Facebook SDK 4(Android)中创建请求 [英] Create a Request in Facebook SDK 4 (Android)

查看:126
本文介绍了在Facebook SDK 4(Android)中创建请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Facebook SDK v4不再使用会话,但是我读了他们的Graph API文档,会话仍然用于创建请求



https://developers.facebook.com/docs/ graph-api / using-graph-api / v2.3

  / *使API调用* / 
new Request(
session,
/ me,
null,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(响应响应){
/ *处理结果* /
}
}
).executeAsync();

令我困惑的是,如何获取请求的会话?使用Facebook Graph API获取用户个人资料数据的最新示例?



任何建议都不胜感激。

解决方案

在Facebook开发人员页面上发布了一个更新日志和升级文章。在你的情况下,这将是一个选项:

  GraphRequest request = GraphRequest.newMeRequest(accessToken,new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject user,GraphResponse response){
/ *处理结果* /
}
})executeAsync();

顺便说一句,他们指定:



< blockquote>

默认情况下,newMeRequest方法从用户对象获取默认字段。如果您需要任何其他字段,或者由于性能原因希望减少响应有效负载,则可以添加字段参数并请求特定字段。


例如:

  GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback (){
@Override
public void onCompleted(
JSONObject对象,
GraphResponse响应){
//应用程序代码
}
} );
Bundle parameters = new Bundle();
parameters.putString(fields,id,name,link);
request.setParameters(parameters);
request.executeAsync();

我希望我的答案可以帮助你,这是我在stackoverflow中的第一个答案。问候。



参考: Facebook Android SDK升级


As I understand, Facebook SDK v4 doesn't use the Session anymore, but I read in their Graph API document, the session is still used to create the Request

https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3

/* make the API call */
new Request(
    session,
    "/me",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

It's confusing me, and how can I get the session for Request? Any latest example to get the user profile data by using Facebook Graph API?

Any advice is appreciated.

解决方案

On facebook developers' page is published a changelog and upgrade post. In your case this would be an option:

GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject user, GraphResponse response) {
                /* handle the result */
            }
    }).executeAsync();

By the way, they specify this:

By default a newMeRequest method fetches default fields from a user object. If you need any additional fields, or want to reduce the response payload for performance reasons, you can add a fields parameter and request specific fields.

For example:

GraphRequest request = GraphRequest.newMeRequest(
    accessToken,
    new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(
               JSONObject object,
               GraphResponse response) {
            // Application code
        }
    });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();

I hope my answer helps you, being this one my first answer in stackoverflow. Greetings.

Reference: Facebook Android SDK Upgrading

这篇关于在Facebook SDK 4(Android)中创建请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆