在Facebook页面标签上获取用户位置 [英] Getting user location on Facebook page tab

查看:116
本文介绍了在Facebook页面标签上获取用户位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可口可乐似乎已经很好了。即使在任何用户互动之前,他们也可以通过他们的Facebook页面





这个工作在IE中,所以没有涉及HTML5(毕竟,Facebook不会识别导航器

他们如何做?

解决方案

div>

首先,我不认为可以使用javascript来完成。以下是使用服务器端语言(如PHP)的方法。



如果仔细观察您提供的页面(可口可乐登陆标签),您可以看到即使用户没有使用Facebook登录,该国的选择也是如此。



当您设置一个Facebook应用程序时,您可以提供一个选项卡网址。这是相对于您的画布网址的地址,当您的应用程序添加到页面(选项卡内)时,Facebook将从其中提供内容。



如果您执行$ _SERVER超全局变量的var_dump,您将看到一个名为 HTTP_X_FB_USER_REMOTE_ADDR 的变量。这是相应用户的IP地址。获得用户IP地址后,您可以轻松地使用地理位置服务来查找国家:)。



祝你好运!



稍后修改



似乎我在谈论的变量在选项卡内不可用。我只是做了一些更多的测试,或者用户登录或不总是有POST变量名为 fb_sig_country ,这是用户cmes所在国家/地区的TLD。 p>

Coca-Cola seems to have nailed it pretty well. Even before any user interaction, they manage to know where you are at their Facebook page:

This works in IE, so no HTML5 involved (and after all, Facebook won't recognize the navigator object in Javascript).

How do they do this?

解决方案

First of all, I don't think it can be done using javascript. Here's how you can do it using a server side language, like PHP.

If you take a closer look of the page you provided (coca cola landing tab) you can see that selection of the country works even if the user is not logged in with facebook.

When you set up a facebook application you can provide a tab url. This is the address relative to you canvas url from which facebook serves the content when your application is added to a page (inside a tab).

If you do a var_dump of the $_SERVER superglobal variable you would see a variable named HTTP_X_FB_USER_REMOTE_ADDR. This is the IP address of the respective user. After you get the user IP address you can easily use a geolocation service to find out the country :).

Good luck!

later edit

It seems that the variable i was talking about is not available inside a tab. I just did some more tests and either the user is logged in or not you always have the POST variable called fb_sig_country which is the TLD of the country the user cmes from.

这篇关于在Facebook页面标签上获取用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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