I am trying to upload large files in newly created folder in google drive via php .
but when I am not using
$client->setDefer(true);
Then I am getting this error:
Catchable fatal error: Argument 2 passed to Google_Http_MediaFileUpload::__construct() must implement interface Psr\Http\Message\RequestInterface, instance of Google_Service_Drive_DriveFile given, called in /var/www/html/google_drive2/gdrive_upload.php on line 158 and defined in /var/www/html/google_drive2/src/Google/Http/MediaFileUpload.php on line 78
And when I use
$client->setDefer(true);
Then i get this:
Uncaught exception 'Google_Service_Exception' with message 'Not Found' in /var/www/html/google_drive2/src/Google/Http/REST.php on line 118
( ! ) Google_Service_Exception: Not Found in /var/www/html/google_drive2/src/Google/Http/REST.php on line 118
Tried everything but fails. please tell what I am doing wrong.
Here is my complete code of gdrive_upload.php
https://pastebin.com/x96CZg3U
The error:
Google_Service_Exception: Not Found in /path/to/src/Google/Http/REST.php on line 118
occurs when you are passing an invalid reference to the Google API and the API cannot find the resource you are requesting.
For example, when adding a file to Google Drive, this will show when an invalid Google Drive Id is passed.
When adding an event to Google Calendar, this will show when an invalid Google Calendar Id is passed.
Etc.
In your case, the folder is probably not fully set up yet. So you are using a valid Id, but Google has not fully created the folder. Using $client->setDefer(true) probably allows Google enough time to fully set up the folder, which allows your folder Id to validate.
Disclaimer: This error quite possibly appears for other circumstances as well.
Related
I'm working in Symfony 6.0 and PHP 8.1, and the following error appeared in my logs when injecting my custom AWSService into a custom object:
Uncaught PHP Exception BadMethodCallException: "Cannot serialize Symfony\Component\Cache\Adapter\FilesystemAdapter" at /app/vendor/symfony/cache/Traits/FilesystemCommonTrait.php line 176
Channel: request
Context: exception:
{
"class": "BadMethodCallException",
"message": "Cannot serialize Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter",
"code": 0,
"file": "/app/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:176",
"trace": [
"/app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:241",
"/app/vendor/symfony/http-foundation/Session/Session.php:195",
"/app/vendor/symfony/http-kernel/EventListener/AbstractSessionListener.php:132",
"/app/vendor/symfony/event-dispatcher/EventDispatcher.php:270",
"/app/vendor/symfony/event-dispatcher/EventDispatcher.php:230",
"/app/vendor/symfony/event-dispatcher/EventDispatcher.php:59",
"/app/vendor/symfony/http-kernel/HttpKernel.php:185",
"/app/vendor/symfony/http-kernel/HttpKernel.php:173",
"/app/vendor/symfony/http-kernel/HttpKernel.php:74",
"/app/vendor/symfony/http-kernel/Kernel.php:202",
"/app/public/index.php:25"
]
}
I've added other logging throughout the code, and it appears that this happens AFTER my controller exits and returns successfully. I am not clear on how to further debug this issue, since after the controller exits it goes into Symfony-land.
My AWSService handles things like storage to and retrieval from AWS services, such as S3 or DynamoDB. I'm injecting it into an object that keeps the caller's info in the session for easy access, and for the call that throws this error, I'm using it to create a Presigned URL for one of the object's attributes.
The thing that seems strange to me is that the AWSService isn't accessing the filesystem explicitly... it's taking an object and creating a string from it using AWS' $s3->createPresignedRequest() call. Even the AWS docs for createPresignedRequest() imply that the function just spits out an answer based on the settings it was provided:
Important
The URL returned by this method is not validated to ensure that the bucket or key exists, nor does this method ensure that the object allows unauthenticated access.
Further, as stated above, the function call completes with out error, and the Controller that called it also completes without error, before this exception is thrown. So it's hard to believe that the AWSService itself is causing this problem.
Clearly this has something to do with how objects are serialized, but I'm not sure exactly what as this error is pretty vague, and I'm creating a string (not a resource). Any thoughts would be appreciated!
After banging my head against this for a few hours, I finally figured it out... and since I couldn't find anything here at StackOverflow that addresses the issue specifically, here are my notes.
It turns out that Symfony appears to serialize all of the objects in session so that they can be de/re-hydrated after the main processing is complete, and before listeners, post processors, etc. are called.
I got a hint from this StackOverflow post, which told me that resources are not supported in serialized data. But I didn't think that getting a Presigned URL would cause an issue... and as it turned out, that was correct.
I finally created a helper class for the object, and just set the attributes externally instead of internally when the object was constructed. Only at that point did I get a better error:
request.CRITICAL: Uncaught PHP Exception RuntimeException: "Instances of Aws\DynamoDb\DynamoDbClient cannot be serialized" at /app/vendor/aws/aws-sdk-php/src/AwsClient.php line 276
So... because the AWSService included an instance of DynamoDbClient, and because I was putting the AWSService into an object, which was then being stored in the session, Symfony was crashing when the object hit the internal serializer.
I'm not sure why that exception isn't bubbled up better, but... at least now it's documented here. Hope it helps someone else!
Trying to implement the Twilio Client Conference Call Monitor as described here:
https://www.twilio.com/docs/howto/twilio-client-browser-conference-call-monitor
It "sees" ongoing conferences and has output like this:
Found 0 conference(s)
Found 1 conference(s)
etc.
However, it doesn't list the ongoing conferences as desired. No further output is given.
In the ssl_error_log, I found this, which is interesting:
PHP Fatal error: Uncaught exception 'Exception' with message 'Objects
returned by Services_Twilio_Page::getIterator() must be traversable or
implement interface Iterator' in /mypath/call_monitor.php:74\nStack
trace:\n#0 /mypath/call_monitor.php(74): unknown()\n#1 {main}\n
thrown in /mypath/call_monitor.php on line 74
I don't find any results here or on Google for this message, so I'm thinking it's particular to my setup.
I'm using Linux / Apache / PHP Version 5.2.17.
The support team at Twilio advised the following:
...it looks like there's a bug in the example code. Can you change
this:
$conferences = $client->account->conferences->getPage(0, 50, array('Status' => 'in-progress'));
to:
$conferences = $client->account->conferences->getIterator(0, 50, array('Status' => 'in-progress'));
i.e. change "getPage" to "getIterator" ?
This corrected the error I reported, but introduced other issues not within the scope of this question.
I just built an application with the facebook graph API, and it's been running smoothly till now..
Whenever I go to my website I'm now getting the error
Uncaught FacebookApiException: Unsupported operation thrown on line 1254
Here is line 1254
$e = new FacebookApiException($result);
When I ran a debug, this is what I got
Open Graph Warnings That Should Be Fixed
Inferred Property:
The 'og:url' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property:
The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property:
The 'og:description' property should be explicitly provided, even if a value can be inferred from other tags.
Does anyone know what's causing this?
You have to be logged in to the facebook app before you can call the graph API.
I had my API calls outside the
if ($user_is_logged_in)
do this
Should have known, but it was an honest mistake!
I'm attempting to post an open graph action to the Facebook Graph API but receiving an OAuth Exception (#3501) User is already associated to the <object>. That's all well and good, I expect Facebook to throw that exception. I get some other exceptions regarding authenticating a user (maybe with old/stale sessions, whatever).
My question is, has anyone else experienced that this exception is uncatchable in php? In this specific example (of posting graph actions) I am absolutely wrapping the call to the api in a try/catch statement; but I still get the fatal error.
<?php
try {
//publishing to open graph
$this->fb->api('/me/app:action', 'POST', array(
'object' => 'http://www.domain.com/path/to/graph/object',
));
}
catch (Exception $e)
{
/*
We may get here if the user has already posted this action before...
or if our session somehow went sour
or bc facebook is down...
or one of any other 1000 reasons the graph api is currently
sucking...
in any case it doesn't much matter, this is not a mission critical
thing to worry about; if we don't post the graph action - we don't
post the graph action..nbd.
*/
}
The above code is the snippet the publishes the graph action (generalized, because the content of it isn't important to this example).
I realize that the Exception that the Facebook PHP SDK is throwing is a FacebookApiException but that class extends Exception. I can't for the life of me figure out why in the name of all things logical, I can't catch my exception like this.
Has anyone experienced this issue? Is this a bug in the FB PHP SDK? Am I missing something else here? Thanks for your help!
Also, for reference, the relevant parts of the FB PHP SDK are here:
FacebookAPIException Definition (base_facebook.php line 30)
Throwing OAuthException (base_facebook.php line 1105
Edit 5/1/12
After some more investigation, it turns out that this "Exception" isn't really being treated like an exception at all. Typical Exceptions print out a stack trace back to the method call which resulted in throwing the exception. These "OAuthExceptions" do not. Also, typical exceptions pring out their error string a bit differently, for example:
PHP Fatal error: Uncaught exception 'Exception' with message 'foo' /path/to/file.php:10
or
PHP Fatal error: Uncaught exception 'MyException' with message 'stupid php' /path/to/file:10
#0 /path/to/file.php(17): doTest()
#1 {main}
thrown in /path/to/file.php on line 10
In this particular case, we don't get any of that, and it looks much more like a typical fatal error:
PHP Fatal error: Uncaught OAuthException: (#3501) User is already associated \
to the <object> object on a unique action type <action>. Original Action ID: \
123123123
thrown in /path/to/app/libs/fb/base_facebook.php on line 1107, \
referer: http://www.domain.com/path/to/page
I can't make any sense of why this forsaken "Exception" is so weird/uncatchable.
The Solution:
I figured out the answer to my own question; I've added it below - it's developer error, not a bug. The answer is below.
Also, this very well could be part of a bug, if you wanted to say that being able to reference a class definition as a type-hint to the catch definition which didn't exist (or wasn't available in the current namespace) is a bug.
So, something that's not outline above is that I'm utilizing PHP namespaces. This is a big gotchta since namespaces are relatively new to php, it's super easily overlooked I feel. Regardless, it's a pretty silly oversight/error.
If you're in a defined namespace (that is, not the root (\) namespace) you don't have direct access to the Exception class. Instead of php throwing a warning about not knowing what that class is, it just ignores the fact that it doesn't know what it is - and doesn't catch the exception.
Solution 1:
import the exception class:
<?php
use \Exception;
// ...codes
try {
//...codes
}
catch (Exception $e)
{
//...codes
}
Solution 2:
provide the full path to the exception class:
<?php
try {
//.....
}
catch (\Exception $e)
{
// voila.
}
I'm trying to get some values from a WebService, but I'm getting some error messages when accessing from PHP web application or SoapUI.
When I access the service from Visual Studio .NET I get the right values, but I really need to access this from PHP.
Here is the error message:
<faultstring xml:lang="pt-BR">The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'ConsultaFretePedido'. End element 'xmlPedido' from namespace 'http://tempuri.org/' expected. Found element 'Pedido' from namespace ''. Line 6, position 51.</faultstring>
I guess this is the error:
End element 'xmlPedido' from namespace 'http://tempuri.org/' expected.
Found element 'Pedido' from namespace ''. Line 6, position 51.
that means, that you have started with <xmlPedido> but ended with </Pedido>
look at the xml code, that the webservice is giving back, at line 6
I'd recommend using SOAPui to check the WebService.