Solved

PHP CodeBird Twitter - Trends

Posted on 2016-08-11
5
84 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 108

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 108

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now