私は PHP/POST/etc を試して、Web 開発者としての仕事を手伝っています。オンラインで見たチュートリアルなどから、これはうまくいくはずです。ただし、送信をクリックすると、ページは にリダイレクトされますがbagelBack.php
、空白のページがあり、ツイートは送信されません。私は自分のマシンで XAMPP Apache を使用しています。(それが役立つ場合は、HTML ページに jQuery があります)
編集: PHP の 40 行目 ($connection->request
など) で失敗しています。 var_dump
動作しますが、echo
動作しません。私はこれらすべてに慣れていません。これがエラーをスローしないのはなぜですか?
HTML:
<form id="bagelForm" action="bagelBack.php" method="POST">
<label for="twitterName">Twitter Name: </label><input type="text" id="twitterName" name="twitterName"/><br />
<label for="bagelType">Bagel Type: </label><input type="text" id="bagelType" name="bagelType"/><br />
<input type="submit" />
</form>
PHP (主にここから):
<?php
/**
* bagelBack.php
* Example of posting a tweet with OAuth
* Latest copy of this code:
* http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/
* @author Adam Green <140dev@gmail.com>
* @license GNU Public License
*/
$name = "@".$_POST['twitterName'];
$type = $_POST['bagelType'];
$tweet_text = $name.", your ".$type." bagel has finished toasting!";
$result = post_tweet($tweet_text);
echo "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
// Use Matt Harris' OAuth library to make the connection
// This lives at: https://github.com/themattharris/tmhOAuth
require_once('tmhOAuth.php');
// Set the authorization values
// In keeping with the OAuth tradition of maximum confusion,
// the names of some of these values are different from the Twitter Dev interface
// user_token is called Access Token on the Dev site
// user_secret is called Access Token Secret on the Dev site
// The values here have asterisks to hide the true contents
// You need to use the actual values from Twitter
$connection = new tmhOAuth(array(
'consumer_key' => '[redacted]',
'consumer_secret' => '[redacted]',
'user_token' => '[redacted]',
'user_secret' => '[redacted]'
));
// Make the API call
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>