使用表单发布使用PHP和TwitterOAUTH的推文

时间:2017-01-26 13:11:31

标签: php forms twitter

如果有人已经在某个地方回答了这个问题,我真诚地道歉 - 我已经在Stack和Google上搜了几个小时而无法找到正确的答案。我正在使用亚伯拉罕的TwitterOAuth并成功设法显示我之前的推文。但是,我想制作一个允许我向我的帐户发布新推文的表单。该表单似乎在刷新页面时发布,但推文未发布到我的帐户 - 任何帮助都非常感谢!

这是目前的设置: (我已从这篇文章中删除了密钥)

<?php

//keys
$consumer_key = '###';
$consumer_secret = '###';
$access_token = '###';
$access_token_secret = '###';

//include library
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;

//connect to API
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");

// create tweet
$new_status = $connection->post("statuses/update", ["status" => ""]);

//get homepage feed
$statuses = $connection->get("statuses/home_timeline", ["count" => 25, "exclude_replies" => true]);

//get my tweets
$profile = $connection->get("statuses/user_timeline", ["count" => 200, "exclude_replies" => true]);

// display first tweet
// echo($profile[0]->text);
?>

<!DOCTYPE html>

<html>

<head>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,700,800,400italic">
    <link rel="stylesheet" href="custom.css">
</head>

<body>

<div class="jumbotron text-center" style="font-size:48px">Sunil Tweets</div><br>    


    <form method="post" action="index.php">
    <input type="text" id="tweet" name="new tweet"/>
    <input type="submit" value="post tweet"/>
    <input type="hidden" action="<?php echo '$new_status';?>"/>
    </form>


</body>    

</html>

0 个答案:

没有答案