Facebook javascript连接本地主机域

编程入门 行业动态 更新时间:2024-10-08 18:39:06
本文介绍了Facebook javascript连接本地主机域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

应用程序配置不允许使用URL: App的设置不允许一个或多个给定的网址。它必须与网站URL或Canvas URL匹配,否则域必须是应用程序域之一的子域。

是否到期我正在使用Localhost服务器进行测试?我需要购买域名来测试这个还是什么? 或者我需要修改以下代码:

我的代码:

<?php // //使用PHP SDK。从github/facebook/php-sdk include(facebook-php-sdk / src / facebook.php)下载; // //从Facebook应用页面 define('YOUR_APP_ID','321849981247524'); define('YOUR_APP_SECRET','49fd00ce6237aff0af08fd8ca25dbc92'); // //新的Facebook对象与Facebook交互 $ facebook = new Facebook(array('appId'=> YOUR_APP_ID,'secret'=> YOUR_APP_SECRET,)); // //如果用户在Facebook上登录,并且已经向您的应用程序授予了 //的权限,则获取他的数据: $ userId = $ facebook-> getUser (); ?> < html> < head> < style> body {text-align:center; font-size:40px}< / style> < / head> < body> <?php if($ userId){ // //已记录?显示一些数据 $ userInfo = $ facebook-> api('/'+ $ userId); echo< p>您是:< strong>。 $ userInfo ['name']。< / strong>< br />; echo你的出生日期是:$ userInfo ['birthday']。< / p>; } else { // //使用javaascript api打开对话框,执行 // facebook连接进程插入fb:login-button ?> < div id =fb-root>< / div> < fb:login-button scope ='email,user_birthday'>< / fb:login-button> <?php } ?> < script> window.fbAsyncInit = function(){ FB.init({ appId:<?= YOUR_APP_ID?> //当我给出应用程序ID321849981247524或我自己创建它给出错误,它无效 status:true, cookie:true, xfbml:true, oauth:true,}); FB.Event.subscribe('auth.login',function(response){ // ------------------- ----------------------------------- //如果一切都OK,这是回调b $ b window.location.reload(); }); }; (function(d){ var js,id ='facebook-jssdk'; if(d.getElementById(id)){return;} js = d。 createElement('script'); js.id = id; js.async = true; js.src =//connect.facebook/en_US/all.js; d.getElementsByTagName ('head')[0] .appendChild(js); }(document)); < / script> < / body> < / html>

当我在浏览器中运行时显示Facebook按钮,然后单击重定向到新窗口进行FB登录,然后显示上面提到的错误!

解决方案

我知道这是一个旧问题,但这里是一个测试和工作的解决方案,结束在这里寻找答案:

开始应用程序域字段应该留空。

点击下面的添加平台按钮,选择网站。

在新的网站表单中,您可以添加localhost 网址字段:

http:// localhost:3000 /

对于有图像的视觉指南,您可以检查这个答案。

除此之外,您实际上可以使用user123的答案,并映射本地域(例如myproject.dev)和本地开发域必须输入到相同的站点URL 字段中: eg。 myproject.dev/

I am trying to create facebook connect using javascript which gives follwing error:

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

Does is due to I am using Localhost server for testing? Do I need to purchase domain to test this or what? Or do I need to make changes in following code:

my code:

<?php // // uses the PHP SDK. Download from github/facebook/php-sdk include("facebook-php-sdk/src/facebook.php"); // // from the facebook app page define('YOUR_APP_ID', '321849981247524'); define('YOUR_APP_SECRET', '49fd00ce6237aff0af08fd8ca25dbc92'); // // new facebook object to interact with facebook $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, )); // // if user is logged in on facebook and already gave permissions // to your app, get his data: $userId = $facebook->getUser(); ?> <html> <head> <style>body { text-align:center; font-size: 40px }</style> </head> <body> <?php if ($userId) { // // already logged? show some data $userInfo = $facebook->api('/' + $userId); echo "<p>YOU ARE: <strong>". $userInfo['name'] ."</strong><br/>"; echo "Your birth date is: ".$userInfo['birthday']."</p>"; } else { // // use javaascript api to open dialogue and perform // the facebook connect process by inserting the fb:login-button ?> <div id="fb-root"></div> <fb:login-button scope='email,user_birthday'></fb:login-button> <?php } ?> <script> window.fbAsyncInit = function() { FB.init({ appId : <?=YOUR_APP_ID?>, //When I gives app ID "321849981247524" or my own created it gives error that it's not valid status : true, cookie : true, xfbml : true, oauth : true, }); FB.Event.subscribe('auth.login', function(response) { // ------------------------------------------------------ // This is the callback if everything is ok window.location.reload(); }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> </body> </html>

When I run in browser it shows facebook button and on click redirect to new windows to do FB loging but then shows above mentioned error!

解决方案

I know that this is an old question but here is a tested and working solution for anyone who ends up here looking for an answer:

At start App Domains field should be left blank.

Click 'Add Platform' button below and choose 'Website'.

In the new Website form you can add localhost in the Site URL field:

eg. localhost:3000/

For a visual guide with images you can check this answer.

Apart from this, you can actually use user123's answer, and map localhost to a local domain (eg. 'myproject.dev') and the local dev domain must be entered in the same Site URL field: eg. myproject.dev/

更多推荐

Facebook javascript连接本地主机域

本文发布于:2023-11-26 21:37:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机   Facebook   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!