开发者

Is there any way I can get public feed of some user or application without logging in, using Android?

In my Android开发者_StackOverflow中文版 App I want to have contents of a public feed of some Facebook profile.

I don't like to force my to log in for that.

Is it possible after recent API changes from FB?

EDIT:

I should have actually asked another question: can I get pulic Facebook feed on Android without asking user to log in?

I see in answers that there are some offline (permanent?) access_tokens - could I just embed it within my app? How to go about it?


There are 2 ways of doing this:

1) Using App id and secret get access token (no user interaction), and then use it to access feed:

try {
        String APP_ID = "123123123123123123";
        String APP_SECRET = "0123456789abcdef";
        String OWNER_OF_FEED = "barackobama";

        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(
                "https://graph.facebook.com/oauth/access_token?client_id="+ 
                APP_ID + 
                "&client_secret="+APP_SECRET+"&grant_type=client_credentials");

        ResponseHandler<String> responseHandler = new BasicResponseHandler();

        String access_token = client.execute(get, responseHandler);
        // access_token contains sthing like "access_token=XXXXXXXXXX|YYYYYY" , 
        //need to replace pipe (this is ugly!)
        String uri = "https://graph.facebook.com/" + OWNER_OF_FEED + "/feed?"
                + access_token.replace("|", "%7C");

        get = new HttpGet(uri);
        String responseBody = client.execute(get, responseHandler);

        // responseBody contains JSON-encoded feed

        textview.setText(responseBody);

    } catch (Exception ex) {
        ex.printStackTrace();
    }

2) Using RSS feed:

http://www.facebook.com/feeds/page.php?format=rss20&id=6815841748

... in case you wonder: 6815841748 is a Facebook ID of president Obama, Google will tell you how to get it.


I don't think it is possible (but hopefully somebody with a bit more knowledge can say otherwise) without an access token...

you can ask for offline permission so you get a non-expiring access token. Then all you have to do is use that token when requesting for a feed.

For example, https://graph.facebook.com/barackobama/feed (and this is a public page) will not give you feed information unless you supply an access token

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜