PHP JSON在数据库中为每个找到的数据插入

时间:2021-01-18 15:43:07

I am using Facebook API to get the Facebook Pages a user administers on Facebook.

我正在使用Facebook API来获取用户在Facebook上管理的Facebook页面。

Have a look here:

看看这里:

https://graph.facebook.com/100000901920184/accounts/&access_token=217662841620006|20de00ae16afeb68d32319d8.1-100000901920184|BCz2UJbFylKY_eG969GlBR4loqo

What I need to do is to insert in the Database EACH Facebook Page that is found.

我需要做的是在数据库中插入找到的每个Facebook页面。

The DB will be structured in this way:

DB将以这种方式构建:

-ID (autoincrement)
-PageName (the name of the Page)
-PageID (the ID of the page 
-access_token (the Access Token of the Page)
-OwnerID (this is the user ID I will grab from another function I have)

So now do not mind this is for Facebook API. Just think you have those data to grab and you need to insert in the DB the above values for EACH Fan page.

所以现在不要介意这是针对Facebook API的。只是认为您要抓取这些数据,并且您需要在DB中插入EACH Fan页面的上述值。

This can be done with JSON but I really do not know how to grab that data, organize the Data and Insert it in the DB for Each Page.

这可以使用JSON完成,但我真的不知道如何获取数据,组织数据并将其插入每个页面的数据库中。

Can you help me please?

你能帮我吗?

1 个解决方案

#1


1  

$file = json_decode(file_get_contents('https://graph.facebook.com/100000901920184/accounts/&access_token=217662841620006%7C20de00ae16afeb68d32319d8.1-100000901920184%7CBCz2UJbFylKY_eG969GlBR4loqo'));

foreach($file->data as $row){
    $query = "INSERT INTO `table`(`ID`, `PageName`, `PageID`, `access_token`, `OwnerID`) VALUES (0, '".$row->name."', '".$row->id."', '".$row->access_token."', '".getOwnerIdFunction()."')";
    // run Query;
}

#1


1  

$file = json_decode(file_get_contents('https://graph.facebook.com/100000901920184/accounts/&access_token=217662841620006%7C20de00ae16afeb68d32319d8.1-100000901920184%7CBCz2UJbFylKY_eG969GlBR4loqo'));

foreach($file->data as $row){
    $query = "INSERT INTO `table`(`ID`, `PageName`, `PageID`, `access_token`, `OwnerID`) VALUES (0, '".$row->name."', '".$row->id."', '".$row->access_token."', '".getOwnerIdFunction()."')";
    // run Query;
}