为什么我的流 api 代码不回显 php(twitter 应用程序)中的任何内容?

发布于 2024-12-24 22:16:19 字数 2387 浏览 2 评论 0原文

我正在尝试使用 php 中的流 API,我使用 Matt Harris 流式传输代码但是当我使用 exec 函数运行代码时永远不会显示任何单词,也不会显示错误,我如何才能看到 exec 函数的结果或者我做错了什么?

这是我的代码:

<?php

/**
 * Very basic streaming API example. In production you would store the
 * received tweets in a queue or database for later processing.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 4) In a terminal or server type:
 *      php /path/to/here/streaming.php
 * 5) To stop the Streaming API either press CTRL-C or, in the folder the
 *      script is running from type:
 *      touch STOP
 *
 * @author themattharris
 */

function my_streaming_callback($data, $length, $metrics) {
  echo $data .PHP_EOL;
  return file_exists(dirname(__FILE__) . '/STOP');
}

require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'Y1qoRrUSevAnfpzPJiVpQ',
  'consumer_secret' => 'usZvJYGl1y5IRmImyNSVRGyOajMzsBMubzZND7Uh4',
  'user_token'      => '435894914-UHEEk87wPsiYI4tjSOxYiVvcKZdYon5qSxI376nN',
  'user_secret'     => '1MDdrNBaMZLStfHmngmEjaW6Lkfy5cNR9ySXiqaGw',
));

$method = 'https://stream.twitter.com/1/statuses/filter.json';

// show Tweets which contan the word twitter OR have been geo-tagged within
// the bounding box -122.41,37.77,-122.40,37.78 OR are by themattharris

$params = array(
  'track'     => 'soyprole',
  // Around Twitter HQ. First param is the SW corner of the bounding box
  'locations' => '-122.41,37.77,-122.40,37.78',
  'follow'    => '777925' // themattharris
    );

$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');



// output any response we get back AFTER the Stream has stopped -- or it errors
tmhUtilities::pr($tmhOAuth);

以及运行脚本的代码:

<?php


exec("C:\wamp\www\appTwitterNuevo3\script.php");

?>

I am trying to use the Streaming API from php, I use the code from Matt Harris Streaming code but when I run the code with exec function nevers display a single word neither an error, how can I see the result of the exec function or what am I doing wrong?

This is my code:

<?php

/**
 * Very basic streaming API example. In production you would store the
 * received tweets in a queue or database for later processing.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 4) In a terminal or server type:
 *      php /path/to/here/streaming.php
 * 5) To stop the Streaming API either press CTRL-C or, in the folder the
 *      script is running from type:
 *      touch STOP
 *
 * @author themattharris
 */

function my_streaming_callback($data, $length, $metrics) {
  echo $data .PHP_EOL;
  return file_exists(dirname(__FILE__) . '/STOP');
}

require 'tmhOAuth.php';
require 'tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'Y1qoRrUSevAnfpzPJiVpQ',
  'consumer_secret' => 'usZvJYGl1y5IRmImyNSVRGyOajMzsBMubzZND7Uh4',
  'user_token'      => '435894914-UHEEk87wPsiYI4tjSOxYiVvcKZdYon5qSxI376nN',
  'user_secret'     => '1MDdrNBaMZLStfHmngmEjaW6Lkfy5cNR9ySXiqaGw',
));

$method = 'https://stream.twitter.com/1/statuses/filter.json';

// show Tweets which contan the word twitter OR have been geo-tagged within
// the bounding box -122.41,37.77,-122.40,37.78 OR are by themattharris

$params = array(
  'track'     => 'soyprole',
  // Around Twitter HQ. First param is the SW corner of the bounding box
  'locations' => '-122.41,37.77,-122.40,37.78',
  'follow'    => '777925' // themattharris
    );

$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');



// output any response we get back AFTER the Stream has stopped -- or it errors
tmhUtilities::pr($tmhOAuth);

and the code that runs the script:

<?php


exec("C:\wamp\www\appTwitterNuevo3\script.php");

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-12-31 22:16:19
exec("C:\wamp\www\appTwitterNuevo3\script.php");

这不是执行 PHP 文件的方式。另外,您那里有无效的 \ (反斜杠)。

您可能想尝试以下任一方法:

include("C:\\wamp\\www\\appTwitterNuevo3\\script.php");

system("C:\\wamp\\php\\php.exe C:\\wamp\\www\\appTwitterNuevo3\\script.php");
exec("C:\wamp\www\appTwitterNuevo3\script.php");

That's not how you execute a PHP file. Also, you have invalid \ (backslashes) there.

You may want to try either of these :

include("C:\\wamp\\www\\appTwitterNuevo3\\script.php");

or

system("C:\\wamp\\php\\php.exe C:\\wamp\\www\\appTwitterNuevo3\\script.php");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文