Solved

PHP CodeBird Twitter - Trends

Posted on 2016-08-11
5
174 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
  • 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 12

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 12

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 12

Author Closing Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

685 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