Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP CodeBird Twitter - Trends

Posted on 2016-08-11
5
Medium Priority
?
297 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

715 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