如何将Facebook App的accessToken添加到GraphRequest.newGraphPathRequest方法? [英] How to add Facebook App's accessToken to GraphRequest.newGraphPathRequest method?

查看:82
本文介绍了如何将Facebook App的accessToken添加到GraphRequest.newGraphPathRequest方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Facebook Graph Api console复制了以下代码.但是,Android Studio无法识别accessToken.

I copied the code below from Facebook Graph Api console. However, Android Studio doesn't recognize accessToken.

我已经创建了一个Facebook App并且得到了它的acesstoken.但是我不知道在代码中将其添加到何处.如果我只是复制粘贴. 它显示了此错误

I have alread created a Facebook App and I got its acesstoken. But I don't know where to add it in the code. If I just copy and paste. It shows this error

如果我使用AccessToken.getCurrentAccessToken()方法,它将显示此错误:

If I use AccessToken.getCurrentAccessToken() method, it will show this error:

errorMessage:需要访问令牌才能请求此资源

errorMessage: An access token is required to request this resource

这是我的代码:

GraphRequest request = GraphRequest.newGraphPathRequest(
               accessToken,
                "/ibm/events",
                new GraphRequest.Callback() {
                    @Override
                    public void onCompleted(GraphResponse response) {

                        Log.d(TAG, "onCompleted: " + response.toString());
                    }});

Bundle parameters = new Bundle();
        parameters.putString("fields", "name,cover,start_time,end_time,place,description");
        parameters.putString("limit", "3");
        request.setParameters(parameters);
        request.executeAsync();

    }

推荐答案

首先:

通过下面编写的这些简单步骤制作一个Facebook应用:

Make a Facebook app with these simple steps I have written below:

  1. 转到开发人员"标签,然后单击它.
  2. 然后转到网站选项.
  3. 输入所需的应用名称.
  4. 单击创建Facebook应用". 此后,您必须选择类别,然后可以选择页面应用程序". 您的AppId和Appkey是自动创建的. AppSecretKey被混淆.您可以单击显示按钮以查看您的AppId和AppSecurityKey.
  1. Go to Developer tab and click on it.
  2. Then go to Website Option.
  3. Enter the app name which you have want.
  4. Click on Create Facebook App. After this you have to choose category, you can choose App for Pages. Your AppId and Appkey is created automatically. The AppSecretKey is obfuscated. You can click on the show button to see your AppId and AppSecurityKey.

然后选中此链接以生成访问令牌

1.复制并粘贴您的应用程序ID&您的App Secret进入下面的生成器.您可以获取自己的应用ID和通过单击应用程序"主菜单选项,然后选择新创建的应用程序,您的应用程序秘密".

1.Copy and Paste Your App ID & Your App Secret into the generator below. You can get your App ID & your App Secret by clicking on the Apps main menu option and then choosing your newely created App.

  1. 下一步,单击工具"菜单,然后选择"Graph API Exploer". 第1页 在此页面上,您将单击Graph API Explorer选择选项.

  1. Next click the Tools Menu and then choose Graph API Exploer. page1 On this page you will click the Graph API Explorer select option.

然后从列表中选择您的应用程序.在此示例中,我们将使用自定义Feed.

Then choose your Application from the list. In this example we'll use Custom Feed.

现在单击获取访问令牌".这将显示一个选择权限"弹出窗口,如下所示.

Now you click on the Get Access Token. This will show a Select Permissions popup as you will see next.

下一步单击扩展权限"菜单选项,然后单击复选框read_stream,然后单击获取访问令牌".如果您使用我们的插件在Facebook上显示页面,请不要检查read_stream.

Next Click on the Extended Permissions menu option and click the checkbox read_stream and click Get Access Token. DO NOT CHECK read_stream if you are using our plugin to display a Page on facebook.

6.然后单击确定"按钮继续.

6.Then click the Okay button to continue.

在Android中获取事件:您必须下载Android facebook sdk,然后使用此方法在其中访问令牌getCurrentAccessToken().

Fetch Event IN Android : You have to download Android facebook sdk and put you access token there getCurrentAccessToken() in this method.

/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{event-id}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();

事件详细信息

这篇关于如何将Facebook App的accessToken添加到GraphRequest.newGraphPathRequest方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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