一个使用curl发布(get)到twitter的简单函数

author author     2022-12-26     170

关键词:

  1. | <?php
  2.  
  3. // A simple function using Curl to post (GET) to Twitter
  4. // Kosso : March 14 2007
  5.  
  6. // Feel free to do what you like with this.
  7. // It's pretty easy. But I thought I'd just put it out there.
  8. // Curl is your friend.
  9.  
  10. // usage : postToTwitter("myusername","mypassword","hello twitterati! I'm posting this from a PHP script! woo!");
  11.  
  12. /////////////////////////////////////////////////////////////////////
  13.  
  14.  
  15. function postToTwitter($username,$password,$message){
  16.  
  17. // GET the API url via web authentication
  18. // add 'status' param to send a message to Twitter
  19.  
  20. $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
  21.  
  22. $ch = curl_init();
  23. curl_setopt($ch, CURLOPT_URL, $host);
  24. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  26. curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  27. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  28. curl_setopt($ch, CURLOPT_POST, 1);
  29.  
  30. // Go for it!!!
  31. $result = curl_exec($ch);
  32. // Look at the returned header
  33. $resultArray = curl_getinfo($ch);
  34.  
  35. // close curl
  36. curl_close($ch);
  37.  
  38. //echo "http code: ".$resultArray['http_code']."<br />";
  39.  
  40. if($resultArray['http_code'] == "200")
  41. echo "<br />OK! posted to http://twitter.com/".$username."/<br />";
  42. else
  43. echo "eek! yegads! error posting to Twitter";
  44.  
  45. // debug the result
  46. // echo "<pre>";
  47. // print_r($resultArray);
  48. // echo "</pre><hr>";
  49.  
  50. // $sResult = htmlentities($result);
  51. // $sResult = str_replace("&gt;&lt;","&gt;<br />&lt;",$sResult);
  52.  
  53. // echo "<pre>";
  54. // print $sResult;
  55. // echo "</pre>";
  56.  
  57.  
  58. // ok, you can stop reading now
  59.  
  60. // no, seriously. ;p
  61.  
  62. ?> |

无法使用 Twitter API、PHP 和 curl 发布图像和文本?媒体/上传和状态/更新

】无法使用TwitterAPI、PHP和curl发布图像和文本?媒体/上传和状态/更新【英文标题】:CannotpostimageandtextwithTwitterAPI,PHPandcurl?media/uploadandstatuses/update【发布时间】:2021-11-2707:41:23【问题描述】:我可以得到一个image_id但不能用图片更... 查看详情

如何在 PHP CURL 中从 POST 切换到 GET

...述】:我尝试从之前的Post请求切换到Get请求。假设它是一个Get但最终会发布一个帖子。我在PHP中尝试了以下内容:curl_setopt($curl_handle,CURLOPT_POSTFIELDS,null);curl_setopt($curl_h 查看详情

GET 到 POST 更改后身份验证不再有效

...9-1623:56:48【问题描述】:我使用下面的PHP代码成功获取了Twitter用户的时间线(RESTAPI/OAuth1.0a)现在我想在Twitter上关注一个用户。我需要将GET更改为POST请求,现在代码不再有效。错误:[code]=>32[mes 查看详情

使用curl从命令行创建twitter

curl-uusername:password-dstatus="twitteringfromcurl"http://twitter.com/statuses/update.xml 查看详情

Twitter GET 用户/使用多个参数搜索

】TwitterGET用户/使用多个参数搜索【英文标题】:TwitterGETUsers/Searchwithmultipleparameters【发布时间】:2019-02-2620:55:44【问题描述】:我可以使用两个或更多这些参数进行API调用吗?例如全名和位置。Twitter获取用户/搜索API:https://deve... 查看详情

获取twitter推文

...omePHPcodethatcanbeusedtogetformattedHTMLcontainingNnumberoftweetsforagiventwitteruser.<?php/*Description:TwitterPHPcodeAuthor:AndrewMacBeanVersion:1.0.0*/ /**MethodtomaketwitterapicallfortheuserstimelineinXML*/functiontwitter_status($twitter_id){ $c=curl_init(); curl_s... 查看详情

另一个失败的 twitter oAuth cURL 访问令牌请求

】另一个失败的twitteroAuthcURL访问令牌请求【英文标题】:anothertwitteroAuthcURLaccesstokenrequestthatfails【发布时间】:2011-03-1818:01:24【问题描述】:以下函数给出验证错误而不是令牌:无法验证oAuth签名和令牌functionrequest_token()//Seturl$ur... 查看详情

发布到twitter的vim命令

:command-rangeTwitter<line1>,<line2>write++enc=UTF-8!curl--data-urlencode[email protected]--netrc--no-remote-namehttp://twitter.com/statuses/update.xml 查看详情

如何使用 curl 获取与使用 Chrome 完全相同的 GET 请求?

...ngChrome?【发布时间】:2015-04-2921:45:47【问题描述】:我有一个webapihttp://something.com/api,我想使用GET来获取响应正文。这是我的命令:curl"http://something.com/api"当然,它会失败并给出 查看详情

Javascript - 将图像发布到 Twitter 且不重复

】Javascript-将图像发布到Twitter且不重复【英文标题】:Javascript-PostingImagestoTwitterwithNoDuplicates【发布时间】:2020-03-1411:35:48【问题描述】:我正在使用一个名为Twit的NPM包制作一个Twitter机器人,我想知道如何在不发布重复图像的情... 查看详情

UIActivityViewController 不会将 URL 发布到 Twitter 和 Facebook

】UIActivityViewController不会将URL发布到Twitter和Facebook【英文标题】:UIActivityViewControllerwon\'tpostURLtoTwitterandFacebook【发布时间】:2014-08-1223:57:42【问题描述】:我正在使用UIActivityViewController将一些文本、一个URL和一个图像共享到电子... 查看详情

Twitter 搜索 API:通过 HTTParty “未经授权”,但通过 Curl 成功

】Twitter搜索API:通过HTTParty“未经授权”,但通过Curl成功【英文标题】:TwittersearchAPI:"Unauthorized"throughHTTPartybutsuccessfulviaCurl【发布时间】:2013-06-0505:52:48【问题描述】:在我们的Rails应用程序上工作时,我尝试通过HTTParty... 查看详情

Bash CURL GET 请求输出到单个 JSON 文件,包括服务器响应和 CURL 信息

...mation【发布时间】:2022-01-1422:40:08【问题描述】:我正在使用shell脚本执行curl测试,我需要将curl服务器响应连同time_connect、http_code等 查看详情

php中的file_get_contents或curl?

...【问题描述】:在PHP中应该使用file_get_contents或curl中的哪一个来发出HTTP请求?如果file_get_contents可以完成这项工作,是否需要使用curl?使用curl似乎需要更多的行。例如:卷曲:$ch=curl_init(\'h 查看详情

使用 curl 从网站发布到 Facebook 页面

...布时间】:2016-12-1617:36:07【问题描述】:我正在尝试构建一个脚本,在提交按钮时将数据发布到Facebook页面。我创建了一个不会过期的页面访问令牌,但我不知道如何构建URL。graphapiexplorer中的几个测试不断给我:"error":"message":"(#... 查看详情

在 Linux 中使用 cURL 进行 HTTP POST 和 GET [重复]

...uplicate]【发布时间】:2013-02-0508:51:44【问题描述】:我有一个在Windows上用ASP.NET编写的服务器应用程序,它提供Web服务。如何在Linux中使用cURL调用Web服务?【问题讨论】:为了快速构建curl命令,我正在使用这个在线工具:curlbuild... 查看详情

使用 Selenium Python 将文件上传到 Twitter

】使用SeleniumPython将文件上传到Twitter【英文标题】:UploadfiletoTwitterwithSeleniumPython【发布时间】:2021-01-0922:00:38【问题描述】:我正在尝试制作一个twitter机器人,并且我正在使用Selenium和Python。我已经尝试过这个页面的方法:Uploa... 查看详情

发出 GET Curl 请求时使用时间戳参数出错

】发出GETCurl请求时使用时间戳参数出错【英文标题】:ErrorusingtimestampparameterwhenmakingGETCurlrequest【发布时间】:2022-01-2210:04:42【问题描述】:在使用Curl发出GET请求时在日期参数中使用时间戳时,我收到“403Forbidden”错误。这是我... 查看详情