Error :service account does not have bigquery.jobs.create permission - php

I created one service account with role big query admin.I am Using big query PHP API. Let me know if any other permission is required or not?
It gives me an error stating that the:
service account does not have bigquery.jobs.create permission.
I wanted to run a query on bigquery. Please help.
Following is my code:
$service = new Google_Service_Bigquery($client);
$query = new Google_Service_Bigquery_QueryRequest($client);
$query->setQuery('SELECT * FROM [xxx:xxx.xxs] LIMIT 1000;');
$jobs = $service->jobs;
$response = $jobs->query($project_id, $query);
// Do something with the BigQuery API $response data
print_r($response)
;

I ran into this problem using the BQ library for nodejs.
It seems being signed into a user/service account via the CLI is not always enough. My service account was authenticated and had the correct permissions in the GCP SDK Shell, but I still got service account does not have bigquery.jobs.create permission..
I was able to fix this by simply adding the same service account details, using the client library methods. I used https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html.
In the case of nodejs, I just had to add
// Imports BigQuery library
const {BigQuery} = require('#google-cloud/bigquery');
// Create BQ Options - this object is what fixed the issue
const bqOptions = {};
bqOptions.projectId = '*your-project-name*';
bqOptions.keyFilename = '*Path-to-service-account-private-key*';
// Creates BQ client
const bq = new BigQuery(bqOptions);
I know you are using the PHP library, but I think the PHP equivalent would work the same.

Related

How to connect to kafka using username and password for consuming data

I am using this PHP Kafka client library. Our Kafka is installed on server A and producer from different servers adding data in this using Java code, and now I am trying to consume data via PHP from server B. I need to pass the username and password to access data but in documentation, I am not getting any way to pass the username, password, and bootstrap server.
Java team using following details to add data in kafka
spring.kafka.bootstrap-servers=<value-here>
spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='<username>' password='<password>';
Now same, I am trying to achieve via PHP. How I can pass these parameters with my PHP code to consume data.
According to the documentation, try to do:
<?php
$conf = new \RdKafka\Conf();
$conf->set('sasl.jaas.config', "org.apache.kafka.common.security.plain.PlainLoginModule required username='<username>' password='<password>'");
$conf->set('security.protocol', "SASL_SSL");
$conf->set('sasl.mechanism', "PLAIN");
$consumer = new \RdKafka\Consumer($conf);
$consumer->addBrokers("<kafka_servers_list>");
Following is the solution of problem.
$conf = new RdKafka\Conf();
$conf->set('bootstrap.servers', '<pass-server-here>');
$conf->set('sasl.username', '<username>');
$conf->set('sasl.password', '<password>');
$conf->set('security.protocol', 'sasl_ssl');
$conf->set('sasl.mechanism', 'PLAIN');
$conf->set('group.id', 'anygroupID');
$conf->set('debug', 'all');
$rk = new RdKafka\Consumer($conf);

Zoho crm api v2 for php

I am trying to connect with Zoho CRM using PHP. I followed PHP SDK for Zoho CRM and installed the package.
<?php
require 'vendor/autoload.php';
use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
use zcrmsdk\oauth\ZohoOAuth;
$configuration =array("client_id"=>"clientid","client_secret"=>"clientsecret","redirect_uri"=>"redirecturl","currentUserEmail"=>"useremail");
$a = ZCRMRestClient::initialize($configuration);
$oAuthClient = ZohoOAuth::getClientInstance();
$refreshToken = "refreshtoken";
$userIdentifier = "emailid";
$oAuthTokens = $oAuthClient->generateAccessTokenFromRefreshToken($refreshToken,$userIdentifier);
$result = ZCRMRestClient::getModule("Contacts");
print_r($result);
exit;
?>
error I am getting:
Not able to get access token from refresh token, invalid client_id.
But I am using correct credentials to connect Zoho API.
Spent a day on this myself when I set it up.
Make sure that you are using the same domain for the api and the oauth client app.
They have 2 domains:
https://accounts.zoho.com
https://accounts.zoho.eu
If you created the oauth clinet app on one, use the same one for the api endpoint.
Further to this, if you are using accounts_url=https://accounts.zoho.eu in the oauth_configuration.properties file, then you should also set apiBaseUrl=www.zohoapis.eu in the configuration.properties file.
Given the parameters are read from these two properties files, I don't think you need that configuration array.

Accessing a Google BigQuery dataset from a PHP script running on a Google Compute VM instance

I am attempting to access a BigQuery dataset from a PHP script running on a Google Compute VM instance - on which I have installed Bitnami's LAMP stack.
The dataset is owned by another party, but the party has given me a full ownership role to the dataset, using my email address. They have also given me a read role to another dataset, again using my email address.
My PHP script is intended to read data from the dataset tables to which I have been given read permission, massage that data, and write it to tables in the dataset to which I have been given the full ownership role.
I have spent many hours attempting to work out how to setup the correct authorisations, running everything under my email address as mentioned, but to date I am still getting errors of the "you do not have permission..." type either when trying to read data from one dataset or write it to the other.
The BigQuery datasets are not owned by me as mentioned, but I have been given both the Project ID and names of the datasets involved, and the owner of both has used my email address to set up the access permissions discussed above.
Has anyone a simple step-by-step guide as to how to achieve the above. Does the owner of the datasets need two do anything more than as already described? I am finding working through many pages of Google Help very confusing!
You need service account key file, that comes with a different email address. The service account email should be given permission and not your email. Actually both, because one is used by you to work on the UI, the other is on the app you develop.
I've included a full PHP example for you.
You need to setup the service account default credentials see lines with putenv and useApplicationDefaultCredentials(). This is a working code I have using the library https://github.com/google/google-api-php-client
You need to obtain your service account key file from the console: https://console.cloud.google.com/iam-admin/serviceaccounts/
composer.json
{
"require": {
"google/cloud": "^0.13.0",
"google/apiclient": "^2.0"
}
}
php file
# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\ServiceBuilder;
$query="SELECT repository_url,
repository_has_downloads
FROM [publicdata:samples.github_timeline]
LIMIT 10";
$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS='.dirname(__FILE__) . '/.ssh/dummyname-7f0004z148e1.json');//this can be created with other ENV mode server side
$client->useApplicationDefaultCredentials();
$builder = new ServiceBuilder([
'projectId' => 'edited',
]);
$bigQuery = $builder->bigQuery();
$job = $bigQuery->runQueryAsJob($query);
$info=$job->info();
// print_r($info);
// exit;
$queryResults = $job->queryResults();
/*$queryResults = $bigQuery->runQuery(
$query,
['useLegacySql' => true]);*/
if ($queryResults->isComplete())
{
$i = 0;
$rows = $queryResults->rows();
foreach ($rows as $row)
{
$i++;
$result[$i] = $row;
}
}
else
{
throw new Exception('The query failed to complete');
}
print_r($result);

Google API Data Transfer Insert: missing resource.applicationDataTransfer

I'm creating simple PHP script for transfering ownerships of drive files between users in the same domain. I want to use Admin SDK Transfers and Insert method.
Google has documentation about transfers here
I tried to transfer data through their webpage GUI and it went fine. What I can't do is how to make it work with PHP Client library.
Let's say I have prepared object for creating requests to Transfers resource
$transfers = new \Google_Service_DataTransfer($googleConnection);
googleConnection handles service account authorization so i can make requests like this:
$data = $this->transfers->transfers->listTransfers();
This returns data of all existing transfers in domain. Based on documentation and PHP Client library insert operation should work also.
$transferParams = new \Google_Service_DataTransfer_ApplicationTransferParam();
$transferParams->setKey("PRIVACY_LEVEL"); //what kind of docs I want to transfer
$transferParams->setValue(['SHARED', 'PRIVATE']);
$appDataTransfer = new \Google_Service_DataTransfer_ApplicationDataTransfer();
$appDataTransfer->setApplicationTransferParams($transferParams);
$appDataTransfer->applicationId = "iDString"; //set application ID
$newTransfer = New \Google_Service_DataTransfer_DataTransfer();
$newTransfer->setOldOwnerUserId('accountID'); //origin account IDs are placeholders
$newTransfer->setNewOwnerUserId('account2ID'); //destination account
$newTransfer->setApplicationDataTransfers($appDataTransfer);
$result = $this->transfers->transfers->insert($newTransfer); //execute insert
After executing insert I am getting code 400 with message Missing required field: [resource.applicationDataTransfer].
If I test real parameters via web they work.
I must be missing something, because that exception doesn't make sense at all.
I'm also open to alternative solutions.
setApplicationDataTransfers method expects an array of Google_Service_DataTransfer_DataTransfer so you just need to update the following line (note the [] in the params)
$newTransfer->setApplicationDataTransfers([$appDataTransfer]);

Is it possible to add a ticket response as a specific user via the SoftLayer API using the PHP SOAP client?

I'm attempting to use the SoftLayer API (via the PHP client) to add an update to an existing ticket, as a specific user under our main account (a sibling to our API user).
What I'm trying to achieve is that as the API user, I call SoftLayer_Ticket::addUpdate, passing a SoftLayer_Ticket_Update object that looks similar to:
{
editorID: user1_id_here,
editorType: "USER",
entry: 'My update here'
}
I have user1's ID, however when I pass it in the SoftLayer_Ticket_Update object, the update is still attached as the API user:
{
createDate:"2016-05-17T08:24:50-07:00"
editorId:api_users_id
editorType:"USER"
entry:"Another update for our glorious leader..."
id:#########
ticketId:########
}
Snippet of the ticket update code:
$slClient = \SoftLayer_client::getClient("Ticket", $ticketID);
$ticketUpdateObj = new \stdClass();
$ticketUpdateObj->entry = $update;
$ticketUpdateObj->editorId = ######;
$ticketUpdateObj->editor = ######;
$ticketUpdateObj->editorType = "USER";
$result = $slClient->addUpdate($ticketUpdateObj);
...
(do other stuff here)
Is there any way to do this with the SoftLayer API? Or is the issue stemming from permissions given to the API user, or that I'm attempting to add the update as a sibling to the API user? Any help would be appreciated!
Our platform is older, so we are using an older version of the SoftLayer PHP SOAP client (guessing circa 2010/early 2011).
Thank you in advance!
Sorry, that is not possbile you cannot set the editorId, this value is set by the system with the userID of the user who updated the ticket.
Regards

Categories