首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Facebook将用户数据保存到数据库

从Facebook将用户数据保存到数据库
EN

Stack Overflow用户
提问于 2014-06-09 20:17:36
回答 1查看 1.1K关注 0票数 0

我请求Facebook Users tagged_placesFB API V-4

一旦我有了我正在做的数据

代码语言:javascript
复制
<?php  echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>'; ?>

当数据打印在屏幕上时,它看起来就像thic。

代码语言:javascript
复制
[data] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 111111111111111
                            [created_time] => 1905-01-01T08:00:00+0000
                            [place] => stdClass Object
                                (
                                    [id] => 1111111111111
                                    [location] => stdClass Object
                                        (
                                            [latitude] => 36.1313
                                            [longitude] => -95.9373
                                        )

                                    [name] => Tulsa, Oklahoma
                                )

                        )

                    [1] => stdClass Object
                        (
                            [id] => 11111111111
                            [created_time] => 2014-05-30T21:41:11+0000
                            [place] => stdClass Object
                                (
                                    [id] => 111111111111111
                                    [location] => stdClass Object
                                        (
                                            [city] => Okmulgee
                                            [country] => United States
                                            [latitude] => 35.623012460758
                                            [longitude] => -95.972782756346
                                            [state] => OK
                                            [street] => 104 S Morton Ave
                                            [zip] => 74447-5022
                                        )

                                    [name] => Ike's Downtown Pub & Eatery
                                )

                        )

如何将这些信息保存到数据库中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-16 20:15:07

这是如何检索tagged_places中的每个值的方法

代码语言:javascript
复制
 $graphObject['tagged_places']->data->id
 $graphObject['tagged_places']->data->created_time
 $graphObject['tagged_places']->data->place->id
 $graphObject['tagged_places']->data->place->location->latitude
 $graphObject['tagged_places']->data->place->location->longitude
 $graphObject['tagged_places']->data->place->location->state
 $graphObject['tagged_places']->data->place->location->street
 $graphObject['tagged_places']->data->place->location->zip
 $graphObject['tagged_places']->data->place->name

这就是如何将它们插入到MySQL数据库中,

代码语言:javascript
复制
$stmt = $con->prepare('
    INSERT INTO this_should_be_your_table_name
    (id, created_time, place_id, latitude, longitude, state, street, zip, name)
    VALUES
    (?, ?, ?, ?, ?, ?)
');

foreach($graphObject['tagged_places']->data as $data) {
   $stmt->execute(array(
       $data->id,
       $data->created_time,
       $data->place->id,
       $data->place->location->latitude,
       $data->place->location->longitude,
       $data->place->location->state,
       $data->place->location->street,
       $data->place->location->zip,
       $data->place->name
   ));
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24128278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档