繁体   English   中英

使用PHP(OAuth)Abraham Williams在Twitter上发布

[英]Publish on Twitter using PHP (OAuth) Abraham Williams

我有时会研究如何通过编程在Twitter上进行发布,但是在此之前,我得到了下面将显示的代码,仅是即使正确设置了所有内容仍未发送,也没有人对我的设置提出任何建议。必须忘记这样做发送完成了吗?

记住,我使用的是TwiterrOAuth Abraham Williams ,已经申请了1.1 API。 (最新版本的GIT)

下面是代码。

<?php

// Insert your keys/tokens

$consumerKey = 'CONSUMER';
$consumerSecret = 'CSECRET';
$OAuthToken = 'TOKEN';
$OAuthSecret = 'TSECRET';

// Full path to twitterOAuth.php (change OAuth to your own path)
require_once('twitteroauth.php');

// create new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);

// Your Message
$message = "This is a test message.";

// Send tweet
$tweet->post('statuses/update', array('status' => "$message"));

?>

在网站上的多个帖子中进行了研究,并没有给我带来任何解决方案。 记住您什么也没退,什么也没发生。

我的应用程序设置为在Twitter上读写。

如果我检查$ tweet-> post返回false。

这就是var_dump($ tweet)返回的结果

object(TwitterOAuth)#1 (13) { 
["http_code"]=> int(0) 
["url"]=> string(48) "https://api.twitter.com/1.1/statuses/update.json" 
["host"]=> string(28) "https://api.twitter.com/1.1/" 
["timeout"]=> int(30) 
["connecttimeout"]=> int(30) 
["ssl_verifypeer"]=> bool(false) 
["format"]=> string(4) "json" 
["decode_json"]=> bool(true) 
["http_info"]=> array(20) { 
    ["url"]=> string(48) "https://api.twitter.com/1.1/statuses/update.json" 
    ["content_type"]=> NULL 
    ["http_code"]=> int(0) 
    ["header_size"]=> int(0) 
    ["request_size"]=> int(0) 
    ["filetime"]=> int(-1) 
    ["ssl_verify_result"]=> int(0) 
    ["redirect_count"]=> int(0) 
    ["total_time"]=> float(30.02972) 
    ["namelookup_time"]=> float(0.058814) 
    ["connect_time"]=> float(0) 
    ["pretransfer_time"]=> float(0) 
    ["size_upload"]=> float(0) 
    ["size_download"]=> float(0) 
    ["speed_download"]=> float(0) 
    ["speed_upload"]=> float(0) 
    ["download_content_length"]=> float(-1) 
    ["upload_content_length"]=> float(-1) 
    ["starttransfer_time"]=> float(0) 
    ["redirect_time"]=> float(0) } 
["useragent"]=> string(25) "TwitterOAuth v0.2.0-beta2" 
["sha1_method"]=> object(OAuthSignatureMethod_HMAC_SHA1)#2 (0) { } 
["consumer"]=> object(OAuthConsumer)#3 (3) { 
    ["key"]=> string(22) "uqZ5yUGoofxxxxxxxxxxx" 
    ["secret"]=> string(40) "fGpJERhrIAB9RIyQEExxxxxxxxxxx" 
    ["callback_url"]=> NULL 
} 
["token"]=> object(OAuthConsumer)#4 (3) { 
    ["key"]=> string(50) "49596683-Sxxxxxxxxxxxxxxxxxx" 
    ["secret"]=> string(40) "v3Q6pAeE4t1YXaGxxxxxxxxxxxxxx" 
["callback_url"]=> NULL 
} 
}

$ host变量。

public $host = "https://api.twitter.com/1.1/";

尝试添加..

$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret)
$tweet->get('account/verify_credentials'); //<--- Add this.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM