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
Solved

PHP CodeBird Twitter - Trends

Posted on 2016-08-11
5
152 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 109

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 109

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 look for a specific file type in a local or remote server directory using PHP.

809 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