php - 在数组中使用 TwitterOAuth

标签 php mysql twitter

我正在使用 twitter OAuth(由 Abraham 提供),有一个函数我想使用 PHP 在页面中重复多次。我设置了一个数据库,其中包含用户的身份验证 key 和 secret 设置的列表,其中包含以下信息:

Table Name: twitter
Fields: id, key, secret (primary - id, with auto_increment)

我需要这样做,以便为每个键创建一个新连接。为此,我必须使用该函数

$connection = new TwitterOAuth(APP KEY, APP SECRET, USER KEY, USER SECRET);

最初,我每次都在数组中输入,例如 $connection['0']$connection['1'] 等...

使用 mySQL,我收到一条错误,告诉我无法在数组中创建该函数,所以编码天才,你认为我该怎么做?

顺便说一句,这是我的代码:

$con=mysqli_connect("host","username","password","twtid");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT * FROM twitter");
while($row = mysqli_fetch_array($result)) {
        $id = $row['id'];
        $connection = new TwitterOAuth(KEY, SECRET, $row['key'], $row['secret']);
}

错误: fatal error :无法使用 TwitterOAuth 类型的对象作为数组

最佳答案

您没有将对象放入数组中,只是每次通过循环时使用不同的 TwitterOAuth 对象覆盖相同的变量。试试这个:

$connection = array()
while ($row = mysqli_fetch_array($result)) {
    $connection[$row['id']] = new TwitterOAuth(KEY, SECRET, $row['key'], $row['secret']);
}

关于php - 在数组中使用 TwitterOAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20694721/

相关文章:

twitter - 是否可以根据关注者数量搜索 Twitter 用户?

node.js - 获取 HTTP 错误 : 400 Bad Request on GIF or video upload on Twitter

php - 我怎样才能选择一个随机数,但在 PHP 中具有正态概率分布?

mysql - mysql 日期查询失败

Twitter4j : Search for public tweets

php - sql/php 从多个表条目中获取最小值和最大值

Javascript,在SQL中插入字符串

php - 为什么将变量传递给类而不是方法

php - search.php 页面返回错误

php - 我可以将 `new mysqli()` 制作成 php 类吗?