Weebly / weebly-client-php

A php client for using the Weebly Platform API
Other
9 stars 4 forks source link

example code #2

Closed emerika closed 9 years ago

emerika commented 9 years ago

DO you have a simple example of using this class?

databyss commented 9 years ago
// initializing WeeblyClient with $client_id, $client_secret, $user_id, $site_id, $authorization_code
// $authorization_code is the value you get at the end of the oauth process
// it is the base 64 encoding of "access_code-user_id"
$weebly = new \Weebly\WeeblyClient($client_id, $client_secret, $user_id, $site_id, $authorization_code);

// fetch webhooks via api
$webhooks = $weebly->get('/webhooks');
echo "Webhooks:<pre>".var_export($webhooks, true)."</pre>";
emerika commented 9 years ago

Thanks -- so the oauth process must complete before you can use this?

databyss commented 9 years ago

Yes, you would need to get the authorization code to include in the constructor.

Once that is set, you can make any calls you're server has been scoped for.

emerika commented 9 years ago

To be clear, are we talking the 'token' you get after the oauth process is done? Or the 'authorization_code' you get during the auth process? I have gotten through the auth process, have a token and am trying to move on to editing store items'

databyss commented 9 years ago

The access token at the end of the oauth process.

emerika commented 9 years ago

Should this work for reading store information like this?

$wc = new \Weebly\WeeblyClient($CLIENT_ID, $API_SECRET, $auth[ 'user_id'], $auth['site_id'], $auth['token']);

$wc->get('/58912207/sites/448071555340782742/store');

databyss commented 9 years ago

You would use:

$wc->get('/user/sites/448071555340782742/store');

User ID is already part of the request as per the auth token.

emerika commented 9 years ago

Does i make sense for me to make these changes?

const WEEBLY_DOMAIN = 'http://api.weebly.com/';
const WEEBLY_API_DOMAIN = 'http://api.weebly.com//v1';

The call above no longer fails, but seems to return nothing.

emerika commented 9 years ago

I made the above changes and:

removed the extra slash in WEEBLY_API_DOMAIN.

and $wc->get('/user/sites/448071555340782742/store');

takes a long time (10 seconds?) but returns a NULL. Any thoughts?

databyss commented 9 years ago

WEEBLY_DOMAIN should be https://www.weebly.com and WEEBLY_API_DOMAIN should be https://api.weebly.com/v1

The https is important for the API.

emerika commented 9 years ago

Thank you. That solved my problem.