在Facebook Graph API中没有用户登录获取访问令牌? [英] Getting an Access Token Without User Login in Facebook Graph API?

查看:164
本文介绍了在Facebook Graph API中没有用户登录获取访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用facebook graph api rsvp_event。我使用javascript SDK。当用户登录时,一切都很好。但是当用户没有登录时,它会出现错误。



我需要有关谁参加公开活动的信息。我现在明白,我需要一个访问令牌来检索这些信息。因此,我的问题是如果没有用户登录,如何获取访问令牌?是不可能还是有解决方法?是否可以在服务器端使用 app_id client_secret



我正在开发一个ColdFusion页面,但我可以使用PHP如果需要。我支持两者。



我听说过offline_access_permission *。他们已删除此功能。



这可以通过 test user 来实现?说,在服务器端我通过测试用户登录,获取事件信息(只是一个获取请求读取谁参加一个事件),然后注销。在客户端我做休息(用户登录,rsvp到一个事件)。



我不太了解测试用户或其目的。

解决方案



您确定您确实需要用户的访问令牌吗?根据此处的文档,您可能需要:

   - 公共事件的通用access_token(隐私设置为OPEN的用户)
- 对于可以查看非事件的用户的用户access_token公共事件
- 应用程序access_token(对于非公开事件,必须是创建事件的应用程序)
- 页面access_token(对于非公开事件,必须是创建事件的页面)

您可以获取有关如何获取这些令牌的信息 https://developers.facebook.com/docs/concepts/login/access-tokens-and-types /



当某个用户登录时,有权访问该事件时,一个好主意是存储参与用户(在DB中)。



UPDATE用于从FileContent获取数据。



我不知道你正在引用什么API响应但是根据我的经验,他们返回数据:
- 使用JSON序列化 - 您需要使用DeserializeJSON(),例如像这样:

  local.returnStruct = DeserializeJSON(local.requestResult.FileContent); 

  local.returnStruct = DeserializeJSON(local.requestResult.FileContent.toString()); 




  • 我使用一个函数来获取数据:

      function getStructFromQueryString(queryString){
    var ret = StructNew );
    var i = 0;
    var key ='';

    for(i = 1; i LTE ListLen(arguments.queryString,'&'); i ++){
    key = ListGetAt(arguments.queryString,i,'&') ;
    ret [ListFirst(key,'=')] = URLDecode(ListLast(key,=));
    }

    return ret;
    }



I am working with facebook graph api rsvp_event. I am using javascript SDK. Everything works great when the user is logged in. But when the user is not logged in, it gives an error.

I need information about who is attending a public event. I now understand that I would need an access token to retrieve this information. So, my question is how do I get the access token if no user is logged in? Is it impossible or is there a workaround? Could it be done server side using app_id and client_secret?

I am developing a ColdFusion page, but I can use PHP if needed. I have support for both.

I have heard the term *offline_access_permission*. They have removed this feature. Could it be done when it was still available?

EDIT:

Could this be achieved by test user? Say, on server side I login via test user, get the event information (Just a "get" request to read who is attending an event) and then log off. On the client side I do the rest ( user login, rsvp to an event).

I don't know much about "test user" or its purpose. Can anyone confirm whether this can be achieved or not?

Thanks in advance.

解决方案

Are you sure you actually need the user's access token? According to documentation here you may need:

- a generic access_token for public events (those whose privacy is set to OPEN)
- a user access_token for a user who can see the event for non-public events
- an app access_token (for non-public events, must be the app that created the event)
- a page access_token (for non-public events, must be the page that created the event)

You can get info on how to get those tokens here https://developers.facebook.com/docs/concepts/login/access-tokens-and-types/

A good idea could be to store the attending users (in the DB) when you have access to the event - when some user is logged in.

UPDATE for getting the data from FileContent.

I don't know what API response exactly you are referring to, but from my experience they are returning data: - serialized using JSON - you need to use DeserializeJSON(), for example like this:

local.returnStruct = DeserializeJSON( local.requestResult.FileContent );

or

local.returnStruct = DeserializeJSON( local.requestResult.FileContent.toString() );

  • send as something similar to URI. I'm using a function to get that data:

    function getStructFromQueryString( queryString ) {
        var ret = StructNew();
        var i = 0;
        var key = '';
    
        for(i=1; i LTE ListLen(arguments.queryString,'&'); i++) {
            key = ListGetAt(arguments.queryString, i, '&');
            ret[ListFirst(key,'=')] = URLDecode(ListLast(key,"="));
        }
    
        return ret;
    }
    

这篇关于在Facebook Graph API中没有用户登录获取访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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