Server Authentication & WordPress
AnsweredI am trying to create a WordPress plugin for Podio for a client, and I'm having a little trouble with the server authentication flow.
I can get authenticated, pull data, etc - but I can't seem to STAY authenticated. (I need to get a list of items in an app, give the user a chance to choose from that list, and based on their choice, make another api request - it is this second api request that is giving me trouble.)
I'm not quite sure where I'm going wrong, so any help would be much appreciated.
I'm using the php client, server-side authentication, and I've gotten sessions enabled in wp.
Thank you! :)
(if this posts twice, I apologize - I thought I had posted the question, but It didn't seem to go through, so I am posting again.)
-
Thank you for your help, Carl!
Just to make sure I understand the flow... I authenticate, then store the tokens in user_meta.
Once I store the tokens...
$access_token = get_user_meta($user_id, 'access_token');
$refresh_token = get_user_meta($user_id, 'refresh_token');
And then every time I make an api call it would look something like...
$api->oauth->access_token = $access_token;
$api->oauth->refresh_token = $refresh_token;
$podioinfoineed = $api->item->getItems($app_id, array(
'limit' => 10,
'sort_by' => 'title',
'sort_desc' => false,
));etc...?
-
Put the client in debug mode right after initializing it:
$api->debug = true;
Then all communication back and forth will be logged to the PHP Error log and you can go in there to debug.
Or you can print the contents of $api->oauth->access_token to the screen before making the second call
-
right? :)
Thank you Carl - I'm going to keep working on it.
I'm not missing something fundamental about the interaction process with the api, am I?
I should be able to make one api call, ask a user to make a decision based on the results returned in the first call, and then make a second call, (without re-authenticating) right?
-
If both calls happen during the same page requests, yes.
If the calls are not in the same page request you will need to store the access token (in the meta database table or in a session) otherwise the second api call will no longer have access to the access token from the first page request since HTTP is stateless.
Please sign in to leave a comment.
Comments
16 comments