Solved

PHP CodeBird Twitter - Trends

Posted on 2016-08-11
5
246 Views
Last Modified: 2016-08-11
I see that the CodeBird library supports 'Trends' but I'm not sure how to make the call.  

This is what I have so far:

<?php

require_once ('codebird.php');
\Codebird\Codebird::setConsumerKey('REDACTED', 'REDACTED'); 

$cb = \Codebird\Codebird::getInstance();

$cb->setToken('REDACTED', 'REDACTED');

$array = array(
    "ID" => "1"
);

print_r($array);

$trends = $cb->get('trends/place', $array );

print_r($trends);

    if (strpos($trends, 'Rate limit exceeded') !== false) {
        if (file_exists($cache_file)) {
            $data = unserialize(file_get_contents($cache_file));
            $trends = $data['trends'];
            echo $trends;
        }
    } else {
        $data = array('trends' => json_encode($trends), 'timestamp' => time());
        file_put_contents($cache_file, serialize($data));
        echo json_encode($trends);
    }

print_r($trends);

$cb->logout();

?>

Open in new window


This is the error I'm seeing from PHP

[11-Aug-2016 14:18:50 America/New_York] PHP Fatal error:  Uncaught exception 'Exception' with message 'Can't find HTTP method to use for "get".' in /home/pathtofi/public_html/serve/CodeBird/codebird.php:1692
Stack trace:
#0 /home/pathtofi/public_html/serve/CodeBird/codebird.php(826): Codebird\Codebird->_detectMethod('get', Array)
#1 /home/pathtofi/public_html/serve/CodeBird/TwitterTrends.php(16): Codebird\Codebird->__call('get', Array)
#2 /home/pathtofi/public_html/serve/CodeBird/TwitterTrends.php(16): Codebird\Codebird->get('trends/place', Array)
#3 {main}
  thrown in /home/pathtofi/public_html/serve/CodeBird/codebird.php on line 1692

Open in new window


I see Trends/Place in the list of get API methods here:

https://github.com/jublonet/codebird-php/blob/develop/src/codebird.php
0
Comment
Question by:Jeff Darling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41752814
We must be missing something here.  This PHP script contains a parse error, so it could never have run and created an uncaught exception.

In PHP the Exception handler is usually invoked as the result of a try / catch / finally  code block.  You might try catching the Exception, but that said, we might be able to discern the issues without it.
http://php.net/manual/en/language.exceptions.php

I think a start might be to add error_reporting(E_ALL) to the top of the script, and use var_dump() to print out the intermediate variables, such as the $cb object.  Then we can see if these values make sense.

I also have a sinking feeling about this library.  A singleton is a well-known anti-pattern.  We avoid it because it cannot be tested, among other things.  It's like a Global value.  When I see programming like that, I become suspicious of other things.  In this code (without reading thousands of lines) I wonder if the term GET === get?  Method names should not be case-sensitive in PHP, but there are some places where strange constructs can cause them to be case-sensitive, and this code might contain one of them.  Maybe try using GET instead of get on line 16?
0
 
LVL 13

Author Comment

by:Jeff Darling
ID: 41752823
I'll look into the try catch code and  error_reporting and var dump as well.  Thanks for the advice.

I fixed that parse error on line 33 or 35, I don't remember which line.  I had and bare comment block :)  like this */  sorry about that.

The library works for other types of twitter calls.  I can post tweets no problem.
0
 
LVL 13

Author Comment

by:Jeff Darling
ID: 41752880
Ok, I'm getting it now.

I didn't follow the instructions on how to setup the call.

https://github.com/jublonet/codebird-php

$reply = $cb->trends_available($array);

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41752881
Ahh... I wouldn't have found that quickly!
0
 
LVL 13

Author Closing Comment

by:Jeff Darling
ID: 41753000
Got me looking in the right direction.  thanks
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explores several main social media platforms.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question