2013-07-02 21 views
0

我想獲得一個朋友的用戶名只使用那裏的名字。從SQL背景我想,這也只是像[Select] [UID] [From] friend [Where] Name = "friends name".如何使用只有那裏的名​​字得到朋友的UID FQL

所以我的查詢是

$fql_query_url = 'https://graph.facebook.com/' 
    . 'fql?q=SELECT+uid+FROM+friend+WHERE+name=Friends Name' 
    . '&access_token=' . $access_token; 

有什麼錯誤在我的邏輯來這裏?

回答

1

而不是friend FQL table您應該使用user table檢索朋友的uid反對他/她的名字。這是因爲friend表只存儲兩個user之間的關係,而不詳細說明它們。

所以您的查詢應該是如下

SELECT uid 
FROM user 
where name = "Name" and uid in (select uid2 from friend where uid1 = me()) 

而作爲name字段不是可轉位,我們需要使用uid2frienduser表來過濾用戶。

編輯

你的查詢需要更改爲以下工作

$fql_query_url = 'https://graph.facebook.com/fql?' 
    . 'q=SELECT+uid+FROM+user+where+name+%3D+%27User+Name%27+' 
     . 'and+uid+in+%28select+uid2+from+friend+where+uid1+%3D+me%28%29%29' 
     . '&access_token=' . $access_token; 
+0

感謝您的幫助 –

+0

你可以更新你的答案,以配合我遇到麻煩名字PHP語法= 「名字」工作。 –

+0

當我用我的朋友的名字/姓氏替換用戶和名稱時,查詢不會返回任何內容。在api文檔中還有一處我錯過了,你瞭解了所有特殊字符在哪裏相等。例如,你有一個%3D而不是a =。 –