I have been having a terrible amount of trouble with using twitter api 1.1. I am getting an error that tells me the '<' from < ?php is unexpected.
Here's my HTML
<div id="date"><h2>Date/time</h2></div>
<div id="tweet"><h2>Twiddly tweet tweet.</h2></div>
<div id="error"></div>
<script>
$(document).ready(function() {
$.ajax({
type: "GET",
url: "index.php",
dataType: "json",
success: function(data, text){
$(data).find('$string').each(function() {
var date = $(this).find('$date').text();
$('#date').append($('<h2 />', {
text: date
}));
});
},
error: function(xhr, text, error) {
$('#error').text("JSON Error: " + error);
}
});
});
</script>
</body>
Here's my php
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "twittercrap",
'oauth_access_token_secret' => "twittercrap",
'consumer_key' => "twittercrap",
'consumer_secret' => "twittercrap"
);
$url = 'http://ift.tt/1As7grw';
$requestMethod = 'GET';
$getfield = '?screen_name=NYCTSubway&count=2';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, something went wrong.</h3><p>Twitter says:</p><p><em>".$string[errors][0]["message"]."</em></p>";
exit();}
foreach($string as $items)
{
echo $date['created_at']."<h2 />";
echo $tweet['text']."<h2 />";
}
?>
All I want is the latest tweet from @NYCTSubway, and just the date/time and the tweet, no other information. I feel like I'm missing something simple that none of the tutorials has gone over.
Aucun commentaire:
Enregistrer un commentaire