StanScates / Tweet.js-Mod

Basic wrapper for Seaofclouds / Tweet.js that incorporates functionality with Twitter's v1.1 API
MIT License
234 stars 103 forks source link

issue when make APP data equal variable , not static key #2

Closed mohamdio closed 11 years ago

mohamdio commented 11 years ago

hi, i have issue now , like that :

when i use this code private $consumer_key = 'gfgdgbdjdgffhghghghghghghg'; // my Consumer Key

work fine...

but when i use variable instead static key like that : private $consumer_key = $consumer_key_from_theme_options;

give me syntax error ..?

so now how can i use variables instead static number or keys !!! ???

wait your replay thanks.

StanScates commented 11 years ago

Hey Mandooox! So basically I think this comes down to variable scope. Without seeing any of your code, I'd probably suggest you try something like this:

/*
Put this before 'class ezTweet' in the PHP file

(This is all assuming you can successfully set $consumer_key and etc from the Wordpress config)

Get your variables from Wordpress here, IE with get_option(); 

You can look here for more info on WP get_option()
http://codex.wordpress.org/Options_API

*/

$parameters = array(
    'consumer_key' => $consumer_key,
    'consumer_secret' => $consumer_secret,
    'user_token' => $user_token,
    'user_secret' => $user_secret
);

Then, change the __construct() function to something like this:

public function __construct($parameters) { 
    $this->consumer_key = $parameters['consumer_key'];
    $this->consumer_secret = $parameters['consumer_secret'];
    $this->user_token = $parameters['user_token'];
    $this->user_secret = $parameters['user_secret'];

    /* rest of __construct() function... */
}

And finally, at the bottom of the file, change $ezTweet = new ezTweet; to $ezTweet = new ezTweet($parameters);

This will allow you to pass the parameters to the constructor without resorting to global variables :+1:

If you're still having problems, send me an email with a pastebin link to your code and I'll get it working for you :)

mohamdio commented 11 years ago

hi, really i try to do that , but i don't know why doesn't work and if i don't understand good , i created for you the code which i need to add in the file , here : http://pastebin.com/qCiPn2qr , you can see in the first top what i need to do exact

so can you update it with what you talking

thanks for you.

StanScates commented 11 years ago

http://pastebin.com/raw.php?i=xLdJJvs7 Try that and let me know how it goes

mohamdio commented 11 years ago

hi, after make update , still doesn't work just appear ( loading tweets... ) , you can see what i done here : http://pastebin.com/qCiPn2qr note, i write keys number like i will use , but doesn't make it active from theme options panel , i first test it with the data like will get , if you see code you know what i mean

thanks , wait you...

StanScates commented 11 years ago

Try turning on debugging: on line #49 change

private $debug = false; to private $debug = true;

Then look in the Javascript console for any errors being reported, that should tell you what the problem is. (In Chrome, right click on the page with the "Loading twitter feed..." and click "inspect element", then on the right click "console"), there should be some text there explaining what's wrong.

Can you provide a link to a page using tweet.js?

mohamdio commented 11 years ago

hi, sure i check from that , before you tell me and didn't get any errors and this status happened with me before , when i was added incorrect keys. so i see the problem because the keys don't assigns right by variables ...??

StanScates commented 11 years ago

Did you set $debug to true? The errors will be hidden from the JS console without debug enabled

mohamdio commented 11 years ago

hi, yes sure i make it true .. but didn't get any error :(

i see the problem because the variables ...right ? are you try to use variables with your code in any work with you.

StanScates commented 11 years ago

If I use your pastebin here: http://pastebin.com/qCiPn2qr and I comment out the include and put in my twitter OAuth credentials I have no problems, I would make sure that the include() on line 4 is not causing the script to die. Also, what's the path to the file you're running? If it's not /twitter/index.php then the script can't make request to it, which is where you'd specify the alternate path with the modpath option as detailed in the docs. Are you running a PHP version older than 5.1? If you email me a link I can probably tell you more.

mohamdio commented 11 years ago

hi, i found the problem like you say exact because this include : include (TEMPLATEPATH . '/inc/theme-options.php'); // this will get global variables from theme options

when i hidden it , tweets appear fine :) , so why happened that , and now i can't include any files in this file ..?

StanScates commented 11 years ago

That is most likely because TEMPLATEPATH is undefined, probably because you need to include wp-load.php to get that constant.

Here are some relevant articles you can read on the subject: http://frankiejarrett.com/2012/04/the-simplest-way-to-require-include-wp-load-php/ http://wordpress.stackexchange.com/questions/26254/how-to-include-wp-load-php-from-any-location

mohamdio commented 11 years ago

hi, many thanks for you , i will see the links last question :) : now all thing will be okay after twitter closed API 1.0 in 5/3 right ? i mean i should don't worry now about the plugin ...?

and thanks again for your :+1:

StanScates commented 11 years ago

That's correct, the point of this PHP is so it works with Twitter API v1.1

No problem, feel free to open another issue if you have questions. :)

mohamdio commented 11 years ago

thanks , but are you talking about PHP version older than 5.1 ?

StanScates commented 11 years ago

No... the point of this PHP file you're working with is so tweet.js works with the new Twitter API

mohamdio commented 11 years ago

okay .. thanks for you.