2012-05-15 84 views

回答

1

您在用戶表中沒有任何稱爲country的參數。但是你可以使用USER_LOCATION或user_hometown或區域
https://developers.facebook.com/docs/reference/api/user/

對於獲取用戶的位置,您需要從用戶的權限(USER_LOCATION或user_hometown)
https://developers.facebook.com/docs/authentication/permissions/

然後FB.API(「/我「)也會返回國家信息。這將返回位置字段爲Array ([id] => 111227078906045 [name] => Some City, New York)

因此,您將永遠收到該國家。

其他辦法

$signed_request = $facebook->getSignedRequest(); 
    $country = $signed_request["user"]["country"]; 

現在$國家有一個字符串,如 「我們」 的美國和 「GB」 表示英國等

+0

如果用戶沒有user_hometown會發生什麼? – Red

+0

當然你沒有得到。那麼你可以依靠current_locaiton – Venu

+0

我很抱歉,但是用戶也可以改變當前位置,這將破壞代碼...以任何其他方式獲得國家字符串? – Red

1

修改查詢:

FB.api('/me?fields=location,hometown'); 
     //with user_location,user_hometown access tokens 
+0

感謝您的答案! – technophyle

相關問題