I'm trying to upload a file to Google Drive using the the v3 Google Drive SDK:
$this->drive()
->files
->update(
$this->report->getId(),
$this->report, // This is a Google_Service_Drive_DriveFile instance
[
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation())
]
);
And I receive the following exception:
Error calling PATCH https://www.googleapis.com/upload/drive/v3/files/ABCDe4FGHvXZTKVOSkVETjktNE0?uploadType=multipart: (403) The resource body includes fields which are not directly writable.
Apparently the issue is caused by $this->report which I obtain in the following way:
// Fetch the latest synchronized report
$latestReport = $this->drive()
->files
->listFiles([
'orderBy' => 'modifiedTime',
'q' => '\''.$this->userEmail.'\' in owners AND name contains \'AppName\'',
])
->getFiles()[0];
$this->report = $this->drive()
->files
->get($latestReport->id);
Probably $this->report, which is an instance of \Google_Service_Drive_DriveFile, contains some fields that are causing issues when set and passed to the update() method.
I was able to solve the problem by passing a new instance of \Google_Service_Drive_DriveFile to the update() method like this:
$this->drive()
->files
->update($this->report->getId(), (new \Google_Service_Drive_DriveFile()), [
'uploadType' => 'multipart',
'data' => file_get_contents($this->getLocalReportLocation()),
'mimeType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
]);
Related
If I put $author='Steven King'; it works without issue, however it does not work with a post variable.
To be "clear" if I hard code the the author in the JSON it will in fact post the message to the SQS queue. This is the expected result, however if I pass the string from the Post Variable e.g. $author=$_POST['author], the message is never delivered.
$message = array(
// Associative array of custom 'String' key names
'Author' => array(
'StringValue' =>$author,
'DataType' => 'String'
),
);
Any thoughts or help on this I would be grateful.
<?php
$author =$_POST["author"];
require 'vendor/autoload.php';
use Aws\Common\Aws;
use Aws\Sqs\SqsClient;
use Aws\Exception\AwsException;
// Get the client from the builder by namespace
$client = SqsClient::factory(array(
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2012-11-05'
));
$queueUrl ='https://sqs.us-west-2.amazonaws.com/blahblahblah';
$message = array(
// Associative array of custom 'String' key names
'Author' => array(
'StringValue' =>$author,
'DataType' => 'String'
),
);
var_dump($message);
$result = $client->sendMessage(array(
'QueueUrl' => $queueUrl,
'MessageBody' => 'An awesome message!',
'MessageAttributes' =>$message,
));
So the issue was caused by the credential provider, which is why it worked in the cli e.g. php posts.php and not in the browser. Because in the CLI it has the correct environment and permissions.
Note: However on AWS SDK example does not include the credential provider only a reference to 'profile' => 'default' which would be thought to grab your default credentials, however that is not the case.
Thank you apache logs!
The fix was to set the right permissions on the /.aws/credentials and ensure
that your $HOME path is set correctly.
On to the next piece. Thanks community.
is it possible to do realtime voice call using nexmo/vonage with PHP or Javascript via web browser?
i used library called nexmo/laravel.
This sample code that i used:
$nexmo = Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => '855969818674'
]],
'from' => [
'type' => 'phone',
'number' => '63282711511'
],
'answer_url' => ['https://gist.githubusercontent.com/jazz7381/d245a8f54ed318ac2cb68152929ec118/raw/6a63a20d7b1b288a84830800ab1813ebb7bac70c/ncco.json'],
'event_url' => [backpack_url('call/event')]
]);
with that code i can send text-to-speech, but how can i do realtime voice conversation person to person?
From the code you shared above, it looks like you might not have instantiated a client instance of the Nexmo PHP SDK, which is necessary to do so. You make an outbound call with an instantiated and authenticated client.
For example, first instantiate a client with the following, supplying the file path to your private key file, your application ID, your API key and your API secret. You can obtain all of those from the Dashboard
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents((NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
Then, once you have a credentialed client, you can then invoke the $client->calls() methods on it. For example:
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'answer_url' => ['https://example.com/answer'],
'event_url' => ['https://example.com/event'],
]);
You can find more information on using the PHP SDK on GitHub. You can also find code snippets, tutorials, and more instructions on our developer portal.
At the moment I am adding a task to Cerb using the API (Docs: https://cerb.ai/docs/api/). I can add and edit comments on the task.
An extension is to add file uploads. The API documentation seems to be extremely limited in terms of file uploads and isn't helping much. I have based my current code on https://cerb.ai/docs/api/endpoints/records/#update, using a custom field linked to the task and posting directly to the API.
The process is as follows:
1 - User inserts information on a Laravel form
2 - Form is submitted, task is created
3 - If the user entered a comment or description, the controller then uses the ID from the newly created task toa dd the comment
4 - If the user adds a file, the controller should then use the same ID from the task to attach the file
Task and comment adding has been done through models, which were previously done directly through the API and reformatted once they worked.
Add Task:
$params = [
'title' => $request->input('title'),
'links' => ['project:'.$request->input('project')],
'priority' => $request->input('priority'),
'status_id' => 2
];
$due_date = $request->input('due');
if(!empty($due_date)){
$params['due'] = strtotime($due_date);
}
$success_task = $task->addUpdateRecord('tasks.add', $params);
Add Comment:
$params = [
'author__context' => 'bot',
'author_id' => 3,
'comment' => empty($comment_input) ? request()->comment : $comment_input,
'target__context' => 'task',
'target_id' => $task_id,
'author' => Auth::user()->name // custom field
];
$success = $comment->addUpdateRecord('comments.add', $params);
The addUpdateRecord() essentially does the same thing as the file upload as below:
$cerb = new CerbApi();
$out = $cerb->put($root.'records/file_bundle/1054.json?expand=custom_', $putfields);
$putfields contains a normal file upload object.
I'm getting the following error on request:
array:2 [▼
"__status" => "error"
"message" => "Unknown command (root/records/task/1054.json)"
]
(root removed for confidentiality)
Has anyone worked with this? Anyone able to assist?
Ended up getting it right by using the attachments record type https://cerb.ai/docs/records/types/attachment/ and creating a model for it with its own addUpdateRecord() method.
I then used the records API to do the post for the file as the first step instead of the last one:
$file_upload = new File;
// Get file contents
$data = file_get_contents($file);
// Base64 encode contents
$data = base64_encode($data);
$file_params = [
'name' => $file->getClientOriginalName(),
'content' => $data
];
// Do upload
$file_success = $file_upload->addUpdateRecord('files.add', $file_params);
// Only need to return the file ID to link it to the task
return $file_success["data"]["id"];
And then using the ID that was being returned to link it to the task:
$task = new Task();
$params = [
'title' => $request->input('title'),
'links' => [
'project:'.$request->input('project'),
'file:'.$file_id
],
'priority' => $request->input('priority'),
'status_id' => 2
];
I hope this helps someone in the future.
Note: Cerb API Version 9.2.0
This is the example adobe have in their documentation.
I have tried with Guzzle:
$client->request('POST', 'transientDocuments', [
'multipart' => [
[
'name' => 'test',
'contents' => fopen('pdfs/test.pdf', 'r'),
'filename' => 'file.pdf',
'headers' => [
'Content-Type' => 'multipart/form-data',
'Content-Transfer-Encoding' => "binary",
]
],
]
]);
fopen returns resource(13) of type (stream)
But every time I get {"code":"NO_FILE_CONTENT","message":"Must provide file body"}.
You should write code to satisfy the following request shown in image below.
Explanation
When u log in with your e-sign account you will be redirected to one of the hosts (like api.in1.echosign.com). You need to put File as form-data parameter key and your file as value. You get Mime-Type based on file extension. In response you will get TransientDocumentId which can be used for the creating and sending agreements etc.
Was stuck with the same but realised that the parameters name and filename to be enclosed in double quotes.
'name' => '"File"',
'filename' => '"file.pdf"',
PS. my code is in .Net, not php
I am writing script that connects to amazon S3 storage. The script is supposed to create 2 buckets:
Bucket is for data
Bucket is for logs
I successfully created both buckets but I can't set up logging. Below is shown code I use for enabling bucket logging
$result = $client->putBucketLogging(array(
'Bucket' => $bucket,
'LoggingEnabled' => array(
'TargetBucket' => $bucket . '-LOG',
'TargetGrants'=>array(
'Grantee'=>array(
'DisplayName'=>'user.name',
'Type'=>'CanonicalUser'
),
),
'TargetPrefix' => 'LOG-',
),
));
In amazon AWS API for PHP version 2 is written that Bucket, LoggingEnabled and Type are mandatory. But the documentation does not say how to exactly implement there parameters.
Could you please help me with structure of config array for putBucketLogging method?
You can also use the service's API documents as a reference, which sometimes contain more details about how to specifically structure some of the data types for requests. The S3 API docs for PUT Bucket Logging have more details about how to specify the grantee.
Also, you should not use capital letters in bucket names (See Rules for Bucket Naming).
After searching in manuals the php array for method putBucketLogging is
$result = $client->putBucketLogging(array(
'Bucket' => $bucket,
'LoggingEnabled' => array(
'TargetBucket' => $bucket . '-log',
'TargetGrants' => array(
'Grant' => array(
'Grantee' => array(
'Type' => 'AmazonCustomerByEmail',
'EmailAddress' => 'email#email.com',
),
'Permission' => 'FULL_CONTROL',
),
),
'TargetPrefix' => 'log-',
),
));
However enabling logging fails with exception that tells me I have to set permissions on log bucket...