0

We have application published with Google apps marketplace. we need to create user on domain where they install our app through API. I have tied the following php code but, i am getting 401 error. Please help.

$oauthOptions = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '2.0',  'scope' => '',
    'signatureMethod' => "HMAC-SHA1",
    'consumerKey' => 'marketplace oauth consumer key',
    'consumerSecret' => 'marketplace oauth consumer secret key' );

$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$token->setToken('');
$token->setTokenSecret('');
$client = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata_Gapps($client, 'domain name');
$gdata->createUser('user34', 'fistname', 'familyname', 'Password');
Palani
  • 1
  • For authentication, have you looked at the [examples](https://code.google.com/p/google-api-php-client/source/browse/#svn%2Ftrunk%2Fexamples%2Fcalendar)? Note you should move to using OAuth2 in a standard flow or "Service Account" flow. See the [documentation](https://developers.google.com/apps-marketplace/building#use_google_services_from_a_simple_web_server_app) for specifics. – jonathanberi Nov 26 '13 at 01:14

1 Answers1

0

You're using the wrong OAuth version - the consumer key and secret work with 1.0, not 2.0. You also don't need to set the scope, token, or token secret to empty strings but I'm not certain whether that would actually cause any problems.

There's a working example of doing two-legged OAuth in PHP at http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/php/two-legged.php. It isn't a marketplace application but the authentication is the same so it should be a good starting point.

hexedpackets
  • 854
  • 10
  • 16