Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用经典ASP进行Facebook服务器端身份验证_Facebook_Asp Classic - Fatal编程技术网

使用经典ASP进行Facebook服务器端身份验证

使用经典ASP进行Facebook服务器端身份验证,facebook,asp-classic,Facebook,Asp Classic,类似于,但我会让我的更精确,所以希望会有一个答案:) 我正在将Facebook登录按钮添加到一个完全采用经典ASP的网站,我是Facebook SDK/API的新手,https://developers.Facebook.com/docs/authentication提供了所有PHP代码示例。我需要通过一些COM函数将一些FB用户信息传递到服务器的数据库,所以我将使用服务器端身份验证。到现在为止,一直都还不错。服务器端auth没有直接给我访问令牌,尽管它给了我一个代码,我主要理解如何将其转换为访

类似于,但我会让我的更精确,所以希望会有一个答案:)

我正在将Facebook登录按钮添加到一个完全采用经典ASP的网站,我是Facebook SDK/API的新手,https://developers.Facebook.com/docs/authentication提供了所有PHP代码示例。我需要通过一些COM函数将一些FB用户信息传递到服务器的数据库,所以我将使用服务器端身份验证。到现在为止,一直都还不错。服务器端auth没有直接给我访问令牌,尽管它给了我一个代码,我主要理解如何将其转换为访问令牌的PHP示例

$token_url = "https://graph.facebook.com/oauth/access_token?"
   . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
   . "&client_secret=" . $app_secret . "&code=" . $code;
 $response = @file_get_contents($token_url);
 $params = null;
 parse_str($response, $params);
 $graph_url = "https://graph.facebook.com/me?access_token=" 
   . $params['access_token'];
 $user = json_decode(file_get_contents($graph_url));
我真的不知道用ASP/VBScript来做上述任何一件事。PHP提供了比ASP多得多的内置函数,比如
urlencode
file\u get\u contents
,一个
parse\u str
,它足够聪明,可以像处理字符串一样处理查询参数,我甚至不知道我是否想要或需要像
json\u decode
这样的东西

对于文件内容,我想尝试一下

fbApiCode = Request.QueryString("code")
    if len(fbApiCode) > 0 then
        set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
        appAuth = "https://graph.facebook.com/oauth/access_token?client_id=" & _
           Application("fbAppId") & "&redirect_uri=" & Application("fbRedirectUri") & "&client_secret=" _
           Application("fbAppSecret") & "&code=" & fbApiCode
        xmlHttp.open("GET", appAuth, false) ' or post?
        accessResponse = xmlHttp.responseText

这是接近正确的方法还是我在跑进兔子洞?如果我不能仅仅用VBScript将代码转换为访问令牌,我将不得不用
FB.getLoginStatus()
用JavaScript获取FB用户的信息(姓名、电子邮件等),然后用AJAX将其发送到我的服务器,我知道这不是非常安全,所以我想避免使用它。

我知道这是一个老线程,但是这个解决方案可能会对某些人有所帮助

您需要使用代码请求令牌,然后使用令牌请求用户信息

<script language="javascript" runat="server">
"use strict";
function getJSON(strOrObject){
    if (typeof strOrObject == "string") {
        return eval("(" + strOrObject + ")");
    }
    return strOrObject;
}
</script>
<%
fbClientToken = [[CLIENTTOKEN]]
fbAppID = [[APPID]]
fbAppSecret = [[APPSECRET]]

fbAuthURL = "https://www.facebook.com/dialog/oauth"
fbTokenURL = "https://graph.facebook.com/v2.3/oauth/access_token"
fbOAuthCallback = [[CALLBACKURL]]
fbScope = "public_profile,email"
if request("go")="login" then
    Randomize
    nonce = Rnd
    response.redirect fbAuthURL & "?response_type=code&client_id=" & fbAppID & "&redirect_uri=" & Server.URLEncode(fbOAuthCallback) & "&scope=" & fbScope & "&state=" & nonce
else
    if request("code") <> "" then       
        information = "client_id=" & fbAppID & "&redirect_uri=" & Server.URLEncode(fbOAuthCallback) & "&client_secret=" & fbAppSecret & "&code=" & request("code")
        Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
        xmlhttp.Open "GET", fbTokenURL & "?" & information, false
        xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
        xmlhttp.send        
        respText = xmlhttp.ResponseText     
        if InStr(respText,"access_token") then
            dim respJSON : set respJSON = getJSON(respText)
            getURL = "https://graph.facebook.com/me?access_token=" & respJSON.access_token
            xmlhttp.Open "GET", getURL, false
            xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
            xmlhttp.send
            respToken = xmlhttp.ResponseText
            %><h1>Token Inspection Response</h1><%
            if InStr(respToken,"{") and InStr(respToken,"}") then
                dim userJSON : set userJSON = getJSON(respToken)
                response.write "<br/>ID: " & userJSON.id
                response.write "<br/>email: " & userJSON.email
                response.write "<br/>first_name: " & userJSON.first_name
                response.write "<br/>last_name: " & userJSON.last_name
                response.write "<br/>name: " & userJSON.name
                response.write "<br/>gender: " & userJSON.gender
                response.write "<br/>locale: " & userJSON.locale
                response.write "<br/>verified: " & userJSON.verified
                response.write "<br/>link: " & userJSON.link
                response.write "<br/>timezone: " & userJSON.timezone
            else
                %><h1>Invalid Inspection Response</h1><%=respToken%><%
            end if          
        else
            %><h1>Invalid Response</h1><%=respText%><%
        end if
    end if
end if
%>

“严格使用”;
函数getJSON(strOrObject){
如果(strOrObject的类型==“字符串”){
返回评估(“+strOrObject+”);
}
返回strOrObject;
}
令牌检查响应INVALID检查响应INVALID响应

这是什么类型的web应用程序?页面标签应用程序?画布应用程序?一个独立的网站?“人们仍然使用经典ASP?”是的。这可能有助于独立的网站,它有自己的注册/登录,我需要与Facebook登录集成。允许新老用户登录Facebook是我们计划使用的唯一Facebook API功能。(是的,这是很多遗留代码;到目前为止,一些控制注册/登录的代码自2004年以来不需要任何更改!)@bkaid,看看窗外。那个地方叫做真实世界。在it中,人们不得不使用传统的技术,如经典的ASP。