Yii Google Webmaster Tools API sitemap submitting - php

I've searched far and wide and have come up with little to nothing on this problem. I've made a module for my Yii app that crawls my website and gathers links to generate a sitemap, I've even made it so that it can run on a cron.
Now I've hit the wall with Google Webmaster Tools API and it's lack of information on how to implement it with OAuth2 for sitemap submission.
Every time I've tried to submit the sitemap I got this response back:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
I would very much appreciate any pointers in any direction.

Maybe this extension can help you:
http://www.yiiframework.com/extension/jgoogleapi/
I'm not sure which is the API for sitemaps and what are its methods but that extension would help you Login to google in "Service" mode that won't need your browser to interact with the login.
You should also before create your application in Google console and then create a service account user type for it.
A paste of my config file when using this extension with Google Analytics:
<?php
/*
* How to obtain a Service Account:
* https://developers.google.com/accounts/docs/OAuth2ServiceAccount
*
*
* (403) User does not have any Google Analytics account.
* http://stackoverflow.com/a/13167988/115050
*
*
*/
return array(
'class' => 'ext.JGoogleAPI.JGoogleAPI',
//Default authentication type to be used by the extension
'defaultAuthenticationType'=>'serviceAPI',
//Account type Authentication data
'serviceAPI' => array(
'clientId' => '...',
'clientEmail' => '...',
'keyFilePath' => dirname(__FILE__).'/../extensions/JGoogleAPI/keys/Analytics-a0e8e345f273.p12',
),
/*
//You can define one of the authentication types or both (for a Service Account or Web Application Account)
webAppAPI = array(
'clientId' => 'YOUR_WEB_APPLICATION_CLIENT_ID',
'clientEmail' => 'YOUR_WEB_APPLICATION_CLIENT_EMAIL',
'clientSecret' => 'YOUR_WEB_APPLICATION_CLIENT_SECRET',
'redirectUri' => 'YOUR_WEB_APPLICATION_REDIRECT_URI',
'javascriptOrigins' => 'YOUR_WEB_APPLICATION_JAVASCRIPT_ORIGINS',
),
*/
'simpleApiKey' => 'AIzaSyAx63Ht-0XmuLdp0-j9zVREKNsCyqXgeUA',
//Scopes needed to access the API data defined by authentication type
'scopes' => array(
'serviceAPI' => array(
'drive' => array(
'https://www.googleapis.com/auth/drive.file',
),
'Analytics'=>array(
'https://www.googleapis.com/auth/analytics.readonly',
),
),
'webappAPI' => array(
'drive' => array(
'https://www.googleapis.com/auth/drive.file',
),
),
),
//Use objects when retriving data from api if true or an array if false
'useObjects'=>false,
);
And how I'm using it:
$api = Yii::app()->JGoogleAPI->getService('Analytics');
$api->data_ga->get(...)

Your access code is invalid. Use refresh token to avoid getting error while authenticating google client.
use the below code:
$gClient->setAccessType("offline");// to get refresh token after expiration of access token
$gClient->setIncludeGrantedScopes(true);

Related

Google Chat API. Can’t create space. Method not found

I'm trying to create a google chat space via making a post request to https://chat.googleapis.com/v1/spaces with Guzzle.
$scopes = [
'https://www.googleapis.com/auth/chat.spaces.create',
'https://www.googleapis.com/auth/chat.bot'
];
// create middleware
$middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
$stack = HandlerStack::create();
$stack->push($middleware);
// create the HTTP client
$client = new Client([
'headers' => ['Content-Type' => 'application/json'],
'handler' => $stack,
'base_uri' => 'https://www.googleapis.com',
'auth' => 'google_auth' // authorize all requests
]);
// make the request
$response = $client->post( 'https://chat.googleapis.com/v1/spaces', [
RequestOptions::JSON => [
'name' => 'ABCDEFG',
'spaceType' => 'DIRECT_MESSAGE',
'threaded' => false,
'displayName' => 'TestSpace'
],
]);
In response I'm getting:
Client error: `POST https://chat.googleapis.com/v1/spaces` resulted in a `404 Not Found` response:
{
"error": {
"code": 404,
"message": "Method not found.",
"status": "NOT_FOUND"
}
}
But if I change the body of the request and add some new invalid fields like this:
$response = $client->post( 'https://chat.googleapis.com/v1/spaces', [
RequestOptions::JSON => [
'name' => 'ABCDEFG',
'spaceType' => 'DIRECT_MESSAGE',
'threaded' => false,
'displayName' => 'TestSpace',
'foo' => 'bar', //added invalid field
],
]);
I'm getting the next response:
Client error: `POST https://chat.googleapis.com/v1/spaces` resulted in a `400 Bad Request` response:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"foo\" at 'space': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "space",
"description": "Invalid JSON payload received. Unknown name \"foo\" at 'space': Cannot find field."
}
]
}
]
}
}
docs:
https://developers.google.com/chat/api/reference/rest/v1/spaces/create
What’s wrong with my original request?
Thanks.
The spaces.create documentation explains this at the top of the page:
Developer Preview: Available as part of the Google Workspace Developer Preview Program, which grants early access to certain features.
This means that the method is only available for users in Google's Developer Preview Program, which seems kind of like a closed beta for some developer features. The link above has a form that you can fill out to join this program, though do note that you also need to be part of the Google Cloud Partner Advantage program to apply.
In short, the method was released not long ago, and is not currently available for everyone. There's also an official blog post explaining this. It may become public in the future, so you'll have to either wait or fill out the applications to become a partner and then join the developer preview.
If you happen to be part of the program already and are still having issues you probably won't find answers among us commoners. You'd want to check out the Partner Advantage support to make sure that the features were enabled for your domain. The developer program documentation above also has a link to the issue tracker to send feedback about this API. You'll only be able to do this as a member, of course.

Getting "AccessDenied" error on amazon pay after success logged in authorized on amazon account

I have implemented PHP SDK for amazon pay and currently I am facing one error, When I click on amazon pay button then one popup will be open for asking login credentials for amazon and after logged in successfully then it will redirect to Address book and payment methods choose page and on that page I am facing this error and Json response that I am getting are as below.
AmazonPay\ResponseParser Object
(
[response] => Array
(
[Status] => 401
[ResponseBody] =>
Sender
AccessDenied
Access denied
11e659e5-6413-4f49-ab38-339472490e5c
)
)
{
"Error": {
"Type": "Sender",
"Code": "AccessDenied",
"Message": "Access denied"
},
"RequestID": "11e659e5-6413-4f49-ab38-339472490e5c",
"ResponseStatus": "401"
}
So please suggest to me if you are aware of this error.
Thanks in advance!
Please set proper country wise config settings on amazon pay configuration file. i.e If your country select UK based then amazon pay sandbox work with GBP and UK only and if you try with another region or currency then you will get this Access Denied error.
Also cross check Amazon Sandbox credentials with that you have set in your file and make sure all settings will be correct.
<?php
namespace AmazonPay;
$config = array(
'merchant_id' => 'YOUR_MERCHANT_ID',
'access_key' => 'YOUR_ACCESS_KEY',
'secret_key' => 'YOUR_SECRET_KEY',
'client_id' => 'YOUR_LOGIN_WITH_AMAZON_CLIENT_ID',
'region' => 'REGION',
'sandbox' => true);
$client = new Client($config);
// Also you can set the sandbox variable in the config() array of the Client class by
$client->setSandbox(true);
Click here to see full documentation for implement amazon pay payment gateway in your website.
Please, you need to set proper country config settings on amazon pay configuration file. for example, If you select Region is UK and Currency is GBP while registration on seller-central account then you have to set 'region' => 'uk' and 'currency'=> 'GBP' in amazon pay configuration file. if you add different region or currency details then you will get Access Denied error.
please..follow below code
<?php
namespace AmazonPay;
$config = array(
'merchant_id' => 'YOUR_MERCHANT_ID',
'access_key' => 'YOUR_ACCESS_KEY',
'secret_key' => 'YOUR_SECRET_KEY',
'client_id' => 'YOUR_LOGIN_WITH_AMAZON_CLIENT_ID',
'region' => 'uk', //set value here
'currency_code' => 'GBP' //set value here
'sandbox' => true);
$client = new Client($config);

MS Graph authentication issue

My company has a WordPress-based intranet and we use Office365. I am hoping to hook into the graph as a global application (without explicit user consent) to grab data. I've gotten all of it working, but am having trouble with the /users/user_name/calendarview endpoint.
I can get valid access tokens using the following:
$auth_request_body = http_build_query( array(
'grant_type' => 'client_credentials',
'client_id' => CLIENT_ID,
'client_secret' => SECRET_KEY,
'resource' => 'https://graph.microsoft.com/'
) );
$response = wp_remote_post( $url, array(
'body' => $auth_request_body
) );
$body = json_decode( wp_remote_retrieve_body( $response ) );
$token_type = $body->token_type;
$access_token = $body->access_token;
and can make several successful calls, for example to the https://graph.microsoft.com/v1/users/user_name endpoint or to the https://graph.microsoft.com/v1/groups/group_id endpoint, however when attempting to reach the https://graph.microsoft.com/v1/users/user_id/calendarview endpoint I get the following response:
[body] => {
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again.",
"innerError": {
"request-id": request_id,
"date": "2018-08-08T21:57:50"
}
}
}
[response] => Array
(
[code] => 403
[message] => Forbidden
)
I am working on my local environment, and for testing purposes I have granted all application / delegated permissions to my local machine (I think .. I'm still not positive how to ensure that newly grated permissions take effect on my local machine).
Any thoughts here?
... Nevermind.
Apparently my newly delegated permissions simply hadn't taken effect yet. This method above DOES work for my scenario.
I think you should confirm whether to grant the appropriate permissions to the application.

Posting on google profile to any user in php

I want to posting on google plus account to any user who authenticate my app i have already create G-Suite account and i can also post on google plus account but i can not post on other user account who already done app authentication i want the functionality like a www.buffer.com application they can easily post on all the users who have verified the google profile so i want to know how they can post on google account and i can't upload activity on google+ accopunt.
$service = new Google_Service_PlusDomains($client);
$activity = new Google_Service_PlusDomains_Activity(
array(
'access' => array(
'items' => array(
'type' => 'domain'
),
'domainRestricted' => true
),
'verb' => 'post',
'object' => array(
'originalContent' => "Post using Google API PHP Client Library! 1" ,
'attachments' => ['image'=>array('url'=>$img_path)]
),
)
);
$newActivity = $service->activities->insert($user->id, $activity);
var_dump($newActivity);
It will successfully post on my google plus account means my G-suit account login but whenever i am going to try to send post to on other account then it is not possible to send post on other normal account it will throwing me error like
ERROR :
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
The Domains API can only be used by G Suite users. It doesn't matter who creates the app, it matters which specific account credentials are on each specific request.

Adobe EchoSign API v5 PHP sample

How can I send someone a document for signing using Adobe EchoSign API v5? For API version 5, I could only find an example using Java. But I need it in PHP. If I use any earlier version it requires an "API key", but in the current version of API, I can't find my API key. I can't even find any sample code in PHP.
There's no longer an API key in the current version as it now uses "Access Token". This is what I did on my PHP application.
Store the Application ID and Client Secret and use it for requesting access token.
If request is successful, store both access token and refresh token and the timestamp in your database.
Access token will expire in 1 hour so you have to check if it already expires.
If access token has expired. Request for refresh token and it should return a new access token.
Replace the access token you stored with the new one you receive and regain access to the API.
I took me a while but I got it working, I hope it helps others, after installing with composer (https://github.com/kevinem/adobe-sign-php/) yo need to create your sandbox page, for me was a index.php in /vendor/kevinem/adobe-sign-php/ then you need to include 2 classes AdobeSign and Psr7 in my case, because I need to upload 2 documments.
require "../../../vendor/autoload.php";
use KevinEm\AdobeSign\AdobeSign;
use GuzzleHttp\Psr7;
this is how I configure my $provider, the call backurl must be the same as the one in the backend of adobe and I changed manually the data center in AdobeSign.php
$provider = new KevinEm\OAuth2\Client\AdobeSign([
'clientId' => 'YOUR_APP_ID',
'clientSecret' => 'YOUR_APP_SECRET',
'redirectUri' => 'YOUR_BACK_URL',
'dataCenter' => 'secure.na2',
'scope' => ['user_login:self',
'agreement_write:self',
'widget_write:self',
'library_write:self',
'agreement_send:self'
]
]);
Then u need to create an array with the URL of all your .pdf documents. my is call $archivos.
$accessToken = $adobeSign->getAccessToken($_GET['code']);
$adobeSign->setAccessToken($accessToken->getToken());
$todosDoc = array();
foreach ($archivos as $doc) {
$file_path = __DIR__.$doc;
$file_stream = Psr7\FnStream::decorate(Psr7\stream_for(file_get_contents($file_path)), [
'getMetadata' => function() use ($file_path) {
return $file_path;
}
]);
$multipart_stream = new Psr7\MultipartStream([
[
'name' => 'File',
'contents' => $file_stream
]
]);
$transient_document = $adobeSign->uploadTransientDocument($multipart_stream);
array_push($todosDoc, $transient_document);
}
$adobeSign->createAgreement([
'documentCreationInfo' => [
'fileInfos' => $todosDoc,
'name' => 'My Document Test',
'signatureType' => 'ESIGN',
'recipientSetInfos' => [
'recipientSetMemberInfos' => [
'email' => 'orlando#yoursigner.com'
],
'recipientSetRole' => [
'SIGNER'
]
],
'mergeFieldInfo' => [
[
'fieldName' => 'Name',
'defaultValue' => 'John Doe'
]
],
'signatureFlow' => 'SENDER_SIGNATURE_NOT_REQUIRED'
]
]);
Adobe Sign has changed its authentication process and instead of using "API key", it now uses "Access-Token" which is more secure.
You can use any PHP based third part rest API client library for the Adobe Sign API calls until Adobe Sign itself provides the SDK for PHP.
Adobe eSign is now using oAuth for authentication, and there are a lot of different libraries for different languag

Categories