POST方法中的ID int限制



我正在使用这个库https://github.com/J7mbo/twitter-api-php使用Twitter API。

我使用.csv来传递Tweet ID,使用GET(showids.php)效果很好:

    <?php
    require('TwitterAPIExchange.php');
    require("auth.php");
    $fichero=fopen("tweets.csv","r");
    while(!feof($fichero)){
        $linea=fgets($fichero);
        $id=(substr($linea,1,18));
        echo ($id."<br />");
        $url = "https://api.twitter.com/1.1/statuses/show.json";
        $requestMethod = "GET";
        $getfield = '?id='.$id;
        $twitter = new TwitterAPIExchange($settings);
        $response = $twitter->setGetfield($getfield)
            ->buildOauth($url, $requestMethod)
        ->performRequest();
    print_r($response);
    echo("<br />");
}
fclose($fichero);

但是,当我使用POST方法(delids.php)时,它会将Tweet ID剪切到int限制。

<?php
require('TwitterAPIExchange.php');
require("auth.php");
$fichero=fopen("tweets.csv","r");
while(!feof($fichero)){
    $linea=fgets($fichero);
        $tid=substr($linea,1,18);
    echo ($tid."<br />");
    $url = sprintf('https://api.twitter.com/1.1/statuses/destroy/%d.json',$tid);
    echo ($url."<br />");
    $method = 'POST';
    $params = array(
    'id'=>$tid,
    );
    $twitter = new TwitterAPIExchange($settings);
    echo $twitter->buildOauth($url,$method)
        ->setPostfields($params)
        ->performRequest();
    echo("<br />");
}
fclose($fichero);

IMG出现错误:int limit

不要使用sprintf,只需通过连接字符串在两者之间添加id:

$url = 'https://api.twitter.com/1.1/statuses/destroy/'.$tid.'.json');

我认为这应该行得通。

可以在这里找到一些解释:http://php.net/manual/en/function.sprintf.phpd接受一个整数,这就是它在最大整数值处截断它的原因。

d-参数被视为整数,并表示为(带符号)十进制数。

最新更新