Using Zend GData library with OAuth and Picasa - php

I am trying to jus get something simple to work using the zend gdata library (for picasa) and some oauth credentials. So I have not idea if I'm passing in the OAuth stuff correctly, and whenever I go to create a gallery it fatals out trying to find '/Zend/Gdata/Photos/Extension/Title.php' which doesn't exist. Title does exist under App/Extension/Title.php. Not sure if it's related to how I'm adding in oauth, or if it's a problem with the autoloader....
$oauthOptions = array(
//'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '2.0',
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET
);
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$service = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken('1/cIxUGEzJtHMt58coKjKEJBBRJV6KFinqpBXl8fX9OG_8');
$accessToken->setTokenSecret('Ykl2junbg06Uy5MncejtmKIy');
$httpClient = $accessToken->getHttpClient($oauthOptions);
$service = new Zend_Gdata_Photos($httpClient); //, "yourCompany-YourAppName-v1"
$entry = new Zend_Gdata_Photos_AlbumEntry();
$entry->setTitle($service->newTitle("test album"));
$service->insertAlbumEntry($entry);

http://www.dbjohn.com/2012/02/29/codeigniter-and-picasa-web-albums
try this

Related

How to upload AWS S3 file to YouTube API

Here is a difficult one... I have managed to adapt the AWS API easily but Google's Oauth2 is not working in my code... I have tried adapting code from StackOverflow and other sources... I have tried the YouTube upload code generator to only fail the upload. I have tried other code available (older Youtube Data API (Google ^2.0)... My biggest problem is that some code examples don't include the API Version which errors in Classes being unidentified... Other code plainly doesn't work... This is my weeks holy grail... Please advise.
<?php
require_once '../aws/aws-autoloader.php';
require_once 'vendor/autoload.php';
use Aws\S3\S3Client;
$chunkSizeBytes = 2 * 1024 * 1024; // 2 mb
$streamName = 's3://gb-football-tribunal-live/1616710690-605d0c226862f-1-0.mp4';
$s3client = S3Client::factory(array(
'version' => 'latest',
'key' => 'MyS3Key',
'secret' => 'MyS3Secret',
'region' => 'eu-west-1' // if you need to set.
));
$s3client->registerStreamWrapper();
$client = new Google_Client();
$client->setApplicationName('cGbYt');
$client->setAuthConfig('client_secret.json');
$client->setAccessType('offline');
$client->setScopes([
'https://www.googleapis.com/auth/youtube.upload',
]);
// Define service object for making API requests.
$service = new Google_Service_YouTube($client);
// Define the $video object, which will be uploaded as the request body.
$video = new Google_Service_YouTube_Video();
// Add 'snippet' object to the $video object.
$videoSnippet = new Google_Service_YouTube_VideoSnippet();
$videoSnippet->setCategoryId('17');
$videoSnippet->setChannelId('UCC7fqHtOns6DtnR7QcaJMaw');
$videoSnippet->setDescription('Testing of Test00001');
$videoSnippet->setTags(['Football', 'Test']);
$videoSnippet->setTitle('Test 00001');
$video->setSnippet($videoSnippet);
// Add 'status' object to the $video object.
$videoStatus = new Google_Service_YouTube_VideoStatus();
$videoStatus->setEmbeddable(true);
$videoStatus->setLicense('youtube');
$videoStatus->setPrivacyStatus('public');
$videoStatus->setUploadStatus('uploaded');
$video->setStatus($videoStatus);
$queryParams = [
'autoLevels' => false,
'notifySubscribers' => true,
'onBehalfOfContentOwner' => 'MyYoutTubeUserID',
'onBehalfOfContentOwnerChannel' => 'MyYouTubeChannelID',
'stabilize' => false,
'uploadType' => 'resumable',
'alt' => 'json',
'fields' => 'items(snippet(id))',
];
$response = $service->videos->insert(
'snippet,status',
$video,
$queryParams,
array(
'data' => file_get_contents($s3client),
'mimeType' => 'application/octet-stream',
'uploadType' => 'multipart'
)
);
print_r($response);
?>

bigcommerce rest api v3 php

I have to implement bigcommerce API integration with PHP
and I am trying to use the official library from https://github.com/bigcommerce/bigcommerce-api-php
and I am not even able to start step 1 here.
Issues:
Basic Auth method
Bigcommerce::configure(array(
'store_url' => 'https://store.mybigcommerce.com',
'username' => 'admin',
'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca'
));
So the question here is how to get a username? bigcommerece user only created using email address so how to get username here?
OAuth method
In order to obtain the auth_token you would consume Bigcommerce::getAuthToken method
$object = new \stdClass();
$object->client_id = 'xxxxxx';
$object->client_secret = 'xxxxx;
$object->redirect_uri = 'https://app.com/redirect';
$object->code = $request->get('code');
$object->context = $request->get('context');
$object->scope = $request->get('scope');
$authTokenResponse = Bigcommerce::getAuthToken($object);
Bigcommerce::configure(array(
'client_id' => 'xxxxxxxx',
'auth_token' => $authTokenResponse->access_token,
'store_hash' => 'xxxxxxx'
));
here the question is what is the $request variable? also, redirect_uri is the bigcommerce store URL or my site URL?
Please can anyone help to get started with this?
It's because that library is a bit out of date with how api accounts are managed. For the basic auth you would use "legacy accounts". You can just use the OAuth method without the oAuth flow (assuming you're trying to connect to your own store, not create an app).
Just the following will work:
Bigcommerce::configure(array(
'client_id' => 'client-id',
'auth_token' => 'access-token',
'store_hash' => 'store-hash'
));
You should get these after creating a user in the dashboard (you can ignore the secret for this use case)

How to use oAuth with Guzzle 5 (or, better, with Guzzle 6)

I'm trying to connect to the WooCommerce API using Guzzle 5 (Guzzle 6 seems not has oAuth options o.O). Woocommerce requires the oAuth authentication method to work.
This is the code I'm using:
<?php
/**
* Example of usage of Guzzle 5 to get information
* from a WooCommerce Store.
*/
require('../vendor/autoload.php');
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
use GuzzleHttp\Exception\RequestException;
$consumer_key = 'my_consumer_key'; // Add your own Consumer Key here
$consumer_secret = 'my_consumer_secret'; // Add your own Consumer Secret here
$store_url = 'http://example.com'; // Add the home URL to the store you want to connect to here
$api_path = '/wc-api/v2/';
$api_end_point = [
'root' => '',
'orders' => 'orders'
];
$base_uri = $store_url . $api_path;
$client = new Client([
'base_url' => $base_uri,
'defaults' => ['auth' => 'oauth']
]);
$oauth = new Oauth1([
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'request_method' => 'query'
]);
$client->getEmitter()->attach($oauth);
try
{
$res = $client->get($api_end_point['orders']);
}
catch (RequestException $e)
{
$res = $e;
if ($e->hasResponse())
{
$res = $e->getResponse();
}
}
print_r($res);
echo $res->getStatusCode();
// "200"
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
This code returns a
woocommerce_api_authentication_error: Invalid Signature - provided
signature does not match
Using pure curl functions (using this package in which I've put some functions I found here), instead, it works and I get all orders and other data I want.
SOME OTHER DETAILS
To use Guzzle 5 and oAuth I use the those composer packages:
"require": {
"guzzlehttp/guzzle": "~5.0"
},
"require-dev": {
"guzzlehttp/oauth-subscriber": "~0.2",
},
It seems there are some things that are different in creating the signature: the one created by the library I've used until now works, but the one created by the oAuth plugin (using the method getSignature()) for Guzzle doesn't and I'm not so used to use oAuth to find the error. Is there someone who can help me identify the problem?
Updating #Aerendir answer
In his pull request, #Aerendir wrote:
In my case, I did the editing as I were trying to connect to the
WooCommerce API version 2 but that version of the API didn't implement
correctly the OAuth Core 1.0a spec. In fact, they fixed this issue in
the version 3 of the API. See Differences between V3 and older
versions.
source: https://github.com/guzzle/oauth-subscriber/pull/42#issuecomment-185631670
So, to make his answer work properly, we need to use wc-api/v3/ instead of wc-api/v2/.
The following code, works using Guzzle 6, oauth and WooCommerce api v3:
use GuzzleHttp\Client,
GuzzleHttp\HandlerStack,
GuzzleHttp\Handler\CurlHandler,
GuzzleHttp\Subscriber\Oauth\Oauth1;
$url = 'http://localhost/WooCommerce/';
$api = 'wc-api/v3/';
$endpoint = 'orders';
$consumer_key = 'ck_999ffa6b1be3f38058ed83e5786ac133e8c0bc60';
$consumer_secret = 'cs_8f6c96c56a7281203c2ff35d71e5c4f9b70e9704';
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$middleware = new Oauth1([
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'token_secret' => '',
'token' => '',
'request_method' => Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMAC
]);
$stack->push($middleware);
$client = new Client([
'base_uri' => $url . $api,
'handler' => $stack
]);
$response = $client->get( $endpoint, [ 'auth' => 'oauth' ] );
echo $response->getStatusCode() . '<br>';
echo $response->getHeaderLine('content-type') . '<br>';
echo $response->getBody();
Now the plugin OauthSubscriber is available only for Guzzle 6.
Testing around again, I've found the bug: it is in the method signUsingHmacSha1()that anyway adds an umpersand (&) to the string to sign and this causes the error from WooCommerce.
I've opened a issue on GitHub and sent a pull request to fix the bug.
The correct way to connect to the WooCommerce API V2 using Guzzle 6 (once the bug is fixed! Take care of the version of the WooCommerce API you connect: the API v3 still doesn't work!) is this:
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
$options = array(
// Add the home URL to the store you want to connect to here (without the end / )
'remoteUrl' => 'http://example.com/',
// Add your own Consumer Key here
'remoteConsumerKey' => 'ck_4rdyourConsumerKey8ik',
// Add your own Secret Key here
'remoteSecretKey' => 'cs_738youconsumersecret94i',
// Add the endpoint base path
'remoteApiPath' => 'wc-api/v2/',
);
$remoteApiUrl = $options['remoteUrl'] . $options['remoteApiPath'];
$endpoint = 'orders';
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$middleware = new Oauth1([
'consumer_key' => $options['remoteConsumerKey'],
'consumer_secret' => $options['remoteSecretKey'],
'token_secret' => '',
'token' => '',
'request_method' => Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMAC
]);
$stack->push($middleware);
$client = new Client([
'base_uri' => $remoteApiUrl,
'handler' => $stack
]);
$res = $client->get($endpoint, ['auth' => 'oauth');
As told, this connection works only with the version 2 of the WooCommerce API.
I'm investigating to understand why the V3 doesn't work.

Post to multiple twitter accounts PHP

i HAVE read many Tutorials on posting to twitter using OAuth like here but i am still unclear on some things.
My requirements is to tweet through multiple accounts for each of which i have a username/password.
Is this possible ? If yes then how do i do it?
I am confused how to get the 4secret keys required for each user account that i have.
1. PHP Class: https://github.com/themattharris/tmhOAuth
2. PHP Function
function tweet($status, $consumer_key, $consumer_secret, $user_token, $user_secret){
include("class.twitter.php");
$tmhOAuth = new tmhOAuth(array(
'consumer_key'=> $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $user_token,
'user_secret' => $user_secret,
));
$tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
'status' => $status
));
}
3. https://dev.twitter.com/apps/new (register an app, get keys foreach account)
4. tweet("yay!", ...);
5. goto 4 but with different keys
Read up on Twitter's authentication scheme, and then have a look at some libraries.

Zend_Service_Twitter Oauth Incorrect Signature

I have sucessfully connected to twitter using Zend_Oauth_Consumer and got an access token, however when i try to use this access token i am getting an error.
This is the code:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();
This outputs:
Zend_Rest_Client_Result Object (
[_sxml:protected] => SimpleXMLElement Object
(
[request] => /1/account/verify_credentials.xml
[error] => Incorrect signature
)
[_errstr:protected] => )
I assume the code is actually correct, its hard to tell as the examples on the ZF site are incomplete.
FWIW i am using Zend Framework 1.10.8
some fields were missing:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token
));
$response = $twitter->account->verifyCredentials();
should be:
$token = unserialize($twsession->access_token); # would be in DB
$twitter = new Zend_Service_Twitter(array(
'username' => $token->screen_name,
'accessToken' => $token,
'consumerKey' => YOUR_APP_CONSUMER_KEY,
'consumerSecret' => YOUR_APP_CONSUMER_SECRET,
'callbackUrl' => YOUR_CALLBACK_URL
));
$response = $twitter->account->verifyCredentials();
To confirm, for a valid signature you need all the same fields that you are using with Zend_Oauth_Consumer

Categories