Create Facebook access token without logging in

大憨熊 提交于 2019-12-11 02:34:16

问题


I want to receive the public posts of a defined facebook page in my app. I already integrated the FacebookSDK and created a new app in the Facebook developer console. My Request looks like this:

new Request(
                null,
                "/176063032413299/feed",
                null,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
                        tv.setText(response.getRawResponse());
                    }
                }
        ).executeAsync();

The server answers, that I need an acceess token. But I don't want my users to be logged in, when they use my app. So is there an option to get an access token without being logged in? I only want to read public data. I am not interested in publishing or reading private posts.

If I use the app access token like this, it still does not work:

new Request(
                null,
                "/176063032413299/feed?access_token=xxx",
                null,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
                        tv.setText(response.getRawResponse());
                    }
                }
        ).executeAsync();

I get the response: "Invalid OAuth access token signature"


回答1:


Even for public posts, you have to authorize the user in order to get access. Either with read_stream to get ALL posts or with user_status to get the posts of the user only.

read_stream will most likely not get approved by Facebook though, see this document: https://developers.facebook.com/docs/facebook-login/permissions/v2.2

Keep in mind that "public" does not mean you can grab it without user authorization. Apps can´t just scrape what they want - scraping is not allowed anyway: https://www.facebook.com/apps/site_scraping_tos_terms.php

Also, of course you can´t create a User Token (which is what you need) without user interaction (login and authorization). Detailed information about Access Tokens can be found in the following links:

  • https://developers.facebook.com/docs/facebook-login/access-tokens/
  • http://www.devils-heaven.com/facebook-access-tokens/

Btw, the docs mention that "Any valid access token is required to view public links." - So you may be able to get links only.

Source: https://developers.facebook.com/docs/graph-api/reference/v2.2/user/feed

For debugging Access Tokens, use the Facebook Debugger: https://developers.facebook.com/tools/debug/

Edit: I just realized that you just want to grab the public feed of a Facebook Page, not a User Profile. For that, you can just use an App Access Token. It´s never expiring and easy to create: App-ID|App-Secret. Check out the docs for more information. Keep in mind that you would need to use a User Token or Page Token if the Page is restricted by age or country.




回答2:


Have a look at https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed/

The permissions needed to be able to request /{page_id}/feed:

  • An access token is required to view publicly shared posts.
  • A user access token is required to retrieve posts visible to that person.
  • A page access token is required to retrieve any other posts.

Meaning you could generate a long-living Page Access Token to be able to retrieve the public Page Posts. As you won't want to store an expiring Access Token in your App, you'll have to create a backend web service to proxy the requests between the Graph API and your app.

See

  • https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens
  • https://developers.facebook.com/docs/facebook-login/access-tokens/#extendingpagetokens
  • https://developers.facebook.com/docs/facebook-login/access-tokens/#refreshtokens

You should also be able to use an App Access Token, which is valid indefinitely.




回答3:


Use client token.

You could also generate and sign your own personal token but you don't want to distribute that.



来源:https://stackoverflow.com/questions/27836175/create-facebook-access-token-without-logging-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!