2012-01-17 162 views
3

我在使用Facebook C#SDK(webforms,asp.net的服務器端)方面相當新穎。你將如何獲取用戶的地址和郵政編碼?這是一個子表,所以我假設你首先必須獲得位置ID,然後從該鏈接到該位置,然後檢索地址,zip等。如何獲取用戶郵政編碼和地址?

任何人都有任何代碼可以共享以指向我一個方向?

回答

1

Facebook 沒有此信息(對於那些使用Facebook Credits的用戶可能不適用,並且已提供此信息在信用卡詳細信息)和 不提供任何方式通過API獲取它。

您可以獲得的唯一信息是家鄉和當前城市(需要用戶的許可)。

更新:
看來,Facebook的確實有這個信息,並提供了一種方法通過請求user_address權限得到它。請參閱張貼在開發者博客瞭解更多詳情User Address and Mobile Phone Number

UPDATE2:
似乎address場不工作了,如意見指出從鏈接張貼上述

UPDATE3:
Improvements to Permissions for Address and Mobile Number的職位,過了三天後又有關於「臨時」禁用此功能的信息。

我們將盡快啓動這些更新,並暫時禁用此功能,直到這些更改準備就緒。

+0

嗯,所以他們不等同於這個老方法(HTTP:// developers.facebook.com/docs/reference/rest/users.getInfo/)? – 2012-01-17 17:28:38

0

我已經找到一種方式來獲得大部分信息:

用戶的信息可以通過調用來檢索,如: https://graph.facebook.com/me (見this link

一旦你有一個用戶您可以通過以下方式獲取位置ID: response.location.id

如果您使用該ID作爲here,您將看到一個如下所示的對象:

{ 
"name": "Hurricane, Utah", 
"is_published": true, 
"is_community_page": true, 
"description": "blah...blah...blah", 
"location": { 
    "city": "Hurricane", 
    "state": "UT", 
    "country": "United States", 
    "latitude": 37.1742, 
    "longitude": -113.326 
}, 
"checkins": 677, 
"were_here_count": 14647, 
"talking_about_count": 1391, 
"category": "City", 
"id": "112177375464163", 
"link": "http://www.facebook.com/pages/Hurricane-Utah/112177375464163", 
"likes": 1730 
} 

我的代碼(JavaScript的):

var locationFunc = function (response) { 
    document.getElementById('loginForm:fbCity').value = response.location.city; 
    document.getElementById('loginForm:fbState').value = response.location.state; 
hiddenBtn = document.getElementById('loginForm:hiddenBtn'); 
hiddenBtn.click(); 
} 

var meFunc = function(response) { 
document.getElementById('loginForm:fbUserID').value = response.id; 
document.getElementById('loginForm:fbFirstName').value = response.first_name; 
document.getElementById('loginForm:fbLastName').value = response.last_name; 
document.getElementById('loginForm:fbEmail').value = response.email; 
FB.api('/' + response.location.id, locationFunc); 
} 

var loginFunc = function (response) { 
FB.api('/me', meFunc); 
} 

function fbAsyncInitLocal() { 
FB.Event.subscribe('auth.authResponseChange', (loginFunc)); 
} 
window.fbAsyncInit = fbAsyncInitLocal; 

我的代碼(JSF - ICEfaces的):

<ice:inputText id="fbUserID" name="fbUserID" immediate="true" style="display:none"/> 
<ice:inputText id="fbFirstName" name="fbFirstName" immediate="true" style="display:none"/> 
<ice:inputText id="fbLastName" name="fbLastName" immediate="true" style="display:none"/> 
<ice:inputText id="fbEmail" name="fbEmail" immediate="true" style="display:none"/> 
<ice:inputText id="fbCity" name="fbCity" immediate="true" style="display:none"/> 
<ice:inputText id="fbState" name="fbState" immediate="true" style="display:none"/> 
<ice:commandButton id="hiddenBtn" name="hiddenBtn" action="#{CustomerBB.fbLoginAction}" immediate="true" style="display:none" /> 
+0

由於我的帖子2天前城市國家和國家不再返回的位置對象。非常令人沮喪。 :( – 2012-09-10 15:55:53

相關問題