-1

I'm still new at this field of API & PHP so any help would be great!

I'm using the Twitter's API "followers/ids" and I would like to insert it into my table in "phpMyAdmin".

After I get the list, I want to insert it into the table that contains two columns - one is for the ID I entered and the other column is for the follower's ID.

I managed to get the list from the Twitter's API but unable to insert it into the table..

thanks for your help!

4

2 回答 2

1

使用这个:https ://dev.twitter.com/docs/api/1.1/get/followers/list将帮助您了解您想对关注者做什么。

SQL 语句应该很容易使用 PHP。创建一个数据库连接并使用 INSERT INTO table_name VALUES (parameter1, paramter2...)。

关于 PHP + mySQL 的信息可以在这里找到:http: //php.net/manual/en/function.mysql-connect.php

所以我要做的是将来自twitter的数据保存在PHP的一个类中,然后将每个数据保存在PHP的一个数组中,完成后我将使用SQL语句:

插入表名值(parameter_for_column1,parameter_for_column2 ... parameter_for_columnN);

然后,这些值可以是您的 PHP 类中的变量。这应该是一个有效的查询,否则请看这里:www.w3schools.com/sql/sql_insert.asp

class dataFromTwitter
{
    public $id;
    public $screen_name;

    public function __construct($setID, $setScreenName)
    {
        $this->id = $setID;
        $this->screen_name = $setScreenName;
    }
}

function insertDB($twitterArray)
{
    foreach($twitterArray as $item)
    {
        mysqli_query($db, "INSERT INTO table_name VALUES ('.$item->id.', '.$item->screen_name.'");
    }
}
于 2013-03-27T16:29:17.917 回答
0

您只需获取关注者 id 并将变量放入insert intosql 语句中,您也可以从这里开始:https://dev.twitter.com/docs/api/1/get/followers/ids

于 2013-03-27T16:11:17.367 回答