使用 Graph FQL 获取朋友当前位置的纬度/经度

发布于 2024-12-27 04:23:20 字数 1405 浏览 0 评论 0原文

我正在尝试使用单个 API 调用来获取用户所有朋友的纬度/经度。我相信我需要编写一个多查询 FQL 语句,但我无法获得正确的语法。

我相信这两个查询需要类似于以下内容:

'"friends":"SELECT uid,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"'

'"location":"SELECT location FROM page WHERE id IN (SELECT current_location_id FROM #friends)"';

我的问题是,不知何故,我需要在第一个查询中获取 current_location 的 ID,以便我可以在第二个查询中引用它,但我只知道如何获取包含 id 的数组。

感谢您的帮助!

澄清:

我并不是想让朋友签到。相反,我想在地理地图上绘制用户所有朋友的“当前位置”(即他们居住的地方)。我可以使用以下 FQL 查询获取用户的“current_location”:

"SELECT uid,sex,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"

该查询返回以下数组:

[current_location] => Array
            (
                [city] => New York
                [state] => New York
                [country] => United States
                [zip] => 
                [id] => 108424279189115
                [name] => New York, New York
            )

其中不包含 current_location 的经度和纬度(上例中为纽约)

因此我现在需要获取 ID current_location 的位置(例如 108424279189115)并运行第二个 FQL 查询,例如:

"SELECT location,name FROM page WHERE page_id = 108424279189115)"

获取 current_location 的纬度和经度。目前,我有一个工作代码,运行第一个 FQL 查询,然后在 php 中提取 page_id,然后运行第二个 FQL 查询以获取 current_location 纬度/经度。但是,出于性能原因,如果可能的话,我只想运行一个多重查询。

I'm trying to get the latitude/longitude of all of a user's friends using a single API call. I believe I need to write a multi-query FQL statement, but I can't get the syntax correct.

I believe the two queries need to be something like the following:

'"friends":"SELECT uid,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"'

'"location":"SELECT location FROM page WHERE id IN (SELECT current_location_id FROM #friends)"';

My problem is that somehow I need to get the ID of the current_location in the first query so that I can reference it in the second query, but I only know how to get an array that contains the id.

Thanks for any help!

Clarification:

I'm not trying to get check-ins of friends. Instead I want to graph the "current_location" (i.e. where they live) of all of a user's friends on a Geo map. I can get a user's "current_location" with the following FQL query:

"SELECT uid,sex,current_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"

This query returns the following array:

[current_location] => Array
            (
                [city] => New York
                [state] => New York
                [country] => United States
                [zip] => 
                [id] => 108424279189115
                [name] => New York, New York
            )

Which does not contain the longitude and latitude of the of the current_location (New York in the above example)

Therefore I now need to take the ID of the current_location (e.g. 108424279189115) and run a second FQL query such as:

"SELECT location,name FROM page WHERE page_id = 108424279189115)"

To get the latitude and longitude of the current_location. Currently, I have a working code that runs the first FQL query, then extracts page_id in php, and then runs a second FQL query to get the current_location latitude/longitude. However, for performance reasons I would like to run only one multi-query if this is possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慵挽 2025-01-03 04:23:20

编辑:

该查询应该通过将第二个查询调整为:

'"location":"SELECT location FROM page WHERE id IN (SELECT current_location.id FROM #friends)"';

在 FB API 中使用数组类型时,您可以通过执行 array.value 来访问任何查询中的值

此外,如果您需要的只是页面的 id,您将通过在第一个查询中执行 current_location.id 可能会获得更好的性能


您将要使用 fql.multiquery,这里有一个类似的答案,可以根据您的需求进行定制:Facebook Graph API 获取所有用户及其状态

FQL 文档关于多重查询位于此处:http://developers.facebook.com/docs/reference/fql/

您还想获取签入对象的纬度/经度吗?如果是这样,您需要查看此资源: http://developers.facebook .com/docs/reference/fql/checkin/

编辑:

我不确定您想要做的事情是否可行。我只是查看了 api 并测试了一些查询,您从朋友那里获取纬度/经度的唯一方法似乎是基于签入,如果需要,您可以从那里获取页面上的详细信息...甚至查看您的第二个查询,current_location_id 在页表中的任何位置都没有引用,从页表中选择位置将为您提供其所属位置的位置信息。也许您可以详细说明您想要实现的目标。

这是我使用 FQL 在 PHP 中编写的多查询语句(它将选择您所有朋友签到的坐标,然后从那里获取与该朋友相关的签到位置的详细信息):

try{
    $multiQuery = "{
        'query1':'SELECT coords, tagged_uids, page_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())',
        'query2':'SELECT name, description FROM page WHERE page_id IN (SELECT page_id FROM #query1)'
    }";

    $param = array(       
         'method' => 'fql.multiquery',       
         'queries' => $multiQuery,       
         'callback' => ''
    );       
    $queryresults = $facebook->api($param);
        print_r($queryresults);
    }
catch(Exception $o){
    print_r($o);
}

Edit:

The query should work by adjusting the second query to:

'"location":"SELECT location FROM page WHERE id IN (SELECT current_location.id FROM #friends)"';

When working with an array type in the FB API you can access the value in any query by doing array.value

Also, if all you need is the page's id, you'll probably get better performance by doing current_location.id in your first query


You're going to want to use a fql.multiquery, there is a similair answer here that can be tailored to your needs: Facebook Graph API get all users and their status

The FQL documentation on multiquery is located here: http://developers.facebook.com/docs/reference/fql/

Also are you trying to get the lat/long of a checkin object? If so you need to take a look at this resource: http://developers.facebook.com/docs/reference/fql/checkin/

Edit:

I'm not sure that what you are trying to do is possible. I just looked through the api and tested some queries, the only way you could get the lat/long from a friend seems to be based on a checkin, from there you can get details on the page if necessary... Even looking at your second query, current_location_id is not referenced anywhere in the page table, and selecting location from the page table is going to give you location info on the place that it pertains to. Maybe you could elaborate more on what you're trying to accomplish.

Here is a multiquery statement I wrote in PHP using FQL (it will select the coordinates of all your friends check ins, then from there get details on the place of the checkin pertaining to that friend):

try{
    $multiQuery = "{
        'query1':'SELECT coords, tagged_uids, page_id FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())',
        'query2':'SELECT name, description FROM page WHERE page_id IN (SELECT page_id FROM #query1)'
    }";

    $param = array(       
         'method' => 'fql.multiquery',       
         'queries' => $multiQuery,       
         'callback' => ''
    );       
    $queryresults = $facebook->api($param);
        print_r($queryresults);
    }
catch(Exception $o){
    print_r($o);
}
若言繁花未落 2025-01-03 04:23:20
fql?q=SELECT location,name FROM page WHERE page_id in (SELECT current_location.id from user where uid in(select uid2 from friend where uid1=me()))

这会给你带来魔力

fql?q=SELECT location,name FROM page WHERE page_id in (SELECT current_location.id from user where uid in(select uid2 from friend where uid1=me()))

this will do the magic for you

帥小哥 2025-01-03 04:23:20
facebook.batch_fql({
    'query1': "SELECT uid, name, current_location.id FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())",
    'query2': "SELECT page_id, name, description, location FROM page WHERE page_id IN (SELECT current_location.id FROM #query1)"
})

将返回两个响应,

一个是好友 UID、姓名及其当前位置 ID 的列表,

另一个是唯一位置 ID 及其姓名、描述和地理位置信息的列表

编辑:如果您查询current_location 使用 FQL,您将在第一个响应中获得完整的经纬度,甚至不需要第二个响应

facebook.batch_fql({
    'query1': "SELECT uid, name, current_location.id FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())",
    'query2': "SELECT page_id, name, description, location FROM page WHERE page_id IN (SELECT current_location.id FROM #query1)"
})

will return two responses

one will be a list of friends UIDs, names and their current locations IDs

the other will be a list of unique location IDs with their name, description and geolocation info

EDIT: if you query for current_location using FQL, you'll get the full latlong in the first response and you don't even need the second one

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文