简体   繁体   English

在客户端获取Facebook访问令牌

[英]Get facebook access token in client side

How can I get my access token in my client side javascript 如何在客户端javascript中获取访问令牌

sample.html(client-side) sample.html(客户端)

<script>

function clickHere(){
$.getJSON(
https://graph.facebook.com/oauth/authorize?client_id=app_id&redirect_uri=http://mydomain.com/index.php, function(data) {
alert(data.code);
})
}

</script>

index.php(server-side) There's a lot of code in it, I will just put the important part. index.php(服务器端)其中包含很多代码,我只介绍其中的重要部分。 (it will retrieve a code that will be needed to get my access token) (它将检索获取我的访问令牌所需的代码)

<?php 
if(isset($_GET['code'])) {
    echo json_encode($_GET['code']);
}
?>

When I open my index.php file it will display my generated code, but when I use my sample.html file to get the code, it will return null. 当我打开index.php文件时,它将显示生成的代码,但是当我使用sample.html文件获取代码时,它将返回null。 I know my question doesn't have a lot of details, its because Its really hard to explain some of the details. 我知道我的问题没有很多细节,这是因为它真的很难解释一些细节。

Please visit this link for better information Facebook Javascript Sdk Connection 请访问此链接以获取更多信息。Facebook Javascript Sdk Connection

You can find demos, and code samples at there. 您可以在此处找到演示和代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM