Welcome Guest, Not a member yet? Register   Sign In
TWITTER API 1.1.
#1

[eluser]Shella[/eluser]
Hi everybody,
I'm getting frustrated with the new Twitter API 1.1.
It's a week that I'm working on it and still I have not solved.

Where I arrived is here throug this code by twitteroauth-master:

Code:
<?php
//session_start();
require_once("twitteroauth-master/twitteroauth/twitteroauth.php"); //Path to twitteroauth library

$twitteruser = "UserName";
$notweets = 1;
$consumerkey = "******************";
$consumersecret = "******************";
$accesstoken = "******************";
$accesstokensecret = "******************";

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}
  
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count;=".$notweets);

//var_dump($tweets);
//echo json_encode($tweets);

echo "created at: ".$tweets[0]->created_at;
echo "<br/>".$tweets[0]->text;


?&gt;

So if I call the page it return correctly the tweet.
The page is here: http://www.shella.it/get_tweet.php

What I cannot do (because of my skill limits) is:

1) use a regex to transform a url in a link that work
2) use this code wherever I want because actually it's outside the logic MVC... I'd like to include it into a page but I can't. Could somebody help me? Would be great even for the community to give something cool and fresh for all the CI users.

Cheers

#2

[eluser]Ckirk[/eluser]
As luck would have it, I'm actually working on this right now for a client.
I can't show you a working example as it's still in development & running on my local machine so I'll explain as best as i can and provide you with some of the files

Solution:
Use JavaScript AJAX method to call your codeigniter script. The codeigniter script returns a JSON list of tweets. The JavaScript uses the JSON data to write the html.

Sources:
TwitterFetcher - A spark plugin for codeigniter which I have modified to output JSON formatted tweets
Twitfeed.js - Modify lines 6, 7 and 22 (twitter username and the ajax call to your codeigniter script)
twitter.css - the stylesheet



The code:
HTML
Code:
&lt;html&gt;
&lt;head&gt;&lt;title>Twitfeed Demo&lt;/title&gt;

[removed][removed]  &lt;!---- this was removed by the ellislab forum - it's the link to the ajax javascript file at hosted at googleapis --&gt;
[removed][removed]   &lt;!---- this was removed by the ellislab forum - it's the link to your twitfeed[dot]js file --&gt;
&lt;link href="twitter.css" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;
&lt;body&gt;

<div id="twitter-feed"></div> &lt;!-- This div will house the twitter feed --&gt;
&lt;/body&gt;
&lt;/html&gt;

CI function
Code:
function ajax()
{
                // Note I've taken this library out of the sparks environment because I've modified it to suit me
                //so it's loaded in the traditional CI way rather than sparks
                $this->load->library('twitterfetcher');
  
                $tweets = $this->twitterfetcher->getTweets(array(
      'consumerKey'       => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'consumerSecret'    => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'accessToken'         => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'accessTokenSecret'   => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'usecache'          => true,
      'count'             => 2,
      'numdays'           => 30
   ));

  echo $tweets;
  
  
}


I think that's enough to give you what you need Smile
#3

[eluser]Shella[/eluser]
Hey there,
thanks to answer so quick. I will try your solution today and I will give a feedback.

Thanks a lot for now. Have a beauuuutyfull day ;-)

Shella
#4

[eluser]Shella[/eluser]
Hey there,
so I tried and I think I'm very close.

Unfortunately I still can not see the tweets. You can see on www.shella.it (on the footer the second column).

With a console tool or firebug i can see:

Code:
Uncaught TypeError: Property '$' of object [object Object] is not a function twitfeed.js:5
(anonymous function)
on tweetfeed.js

So I guess I have a Conflict with JS because I have another .js file that start with

Code:
jQuery.noConflict()(function($){
$(document).ready(function($) {

... but I dunno how to manage it.

Any ideas?
#5

[eluser]Ckirk[/eluser]
That's probably the issue.

You can define an alias for jquery for your twitter feed so that it doesn't conflict with your custom.js

Try this solution

Also I looked at the output from the ajax call. You still need to amend that library to output it in JSON format
#6

[eluser]Shella[/eluser]
Hey!
Sorry I start to be boring I know ;-)

But I'm pretty close.
I try the solution you suggested and yes... it works.

Unfortunately I got an error in a pop up that say:

Quote:parsererror - Unexpected token A

Any idea what it is related to?
Maybe is related to what you say:

Quote:You still need to amend that library

but I dunno what you mean :-s

You can see the error appearing just going on my website www.shella.it

Thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB