Thanks. Yeah, I got that working somehow. When I tried it before I got an 
error. I'm now getting a 400 error from google, however. Here's the $tx 
object now:

$VAR1 = bless( {
                 'req' => bless( {
                                   'method' => 'POST',
                                   'content' => bless( {
                                                         'parts' => [
                                                                      bless( 
{
                                                                            
   'asset' => bless( {
                                                                            
                       'content' => 'GET 
/gmail/v1/users/[email protected]/messages/165eb111fcf21503'
                                                                            
                     }, 'Mojo::Asset::Memory' ),
                                                                            
   'headers' => bless( {
                                                                            
                         'headers' => {
                                                                            
                                        'content-type' => [
                                                                            
                                                            
'application/http'
                                                                            
                                                          ]
                                                                            
                                      }
                                                                            
                       }, 'Mojo::Headers' ),
                                                                            
   'events' => {
                                                                            
                 'read' => [
                                                                            
                             sub { "DUMMY" }
                                                                            
                           ]
                                                                            
               },
                                                                            
   'read' => $VAR1->{'req'}{'content'}{'parts'}[0]{'events'}{'read'}[0]
                                                                            
 }, 'Mojo::Content::Single' )
                                                                    ],
                                                         'events' => {
                                                                       
'read' => [
                                                                            
       sub { "DUMMY" }
                                                                            
     ]
                                                                     },
                                                         'headers' => bless( 
{
                                                                            
   'headers' => {
                                                                            
                  'accept-encoding' => [
                                                                            
                                         'gzip'
                                                                            
                                       ],
                                                                            
                  'content-type' => [
                                                                            
                                      'mulitpart/mixed'
                                                                            
                                    ],
                                                                            
                  'authorization' => [
                                                                            
                                       'Bearer REAL_TOKEN_HERE'
                                                                            
                                     ],
                                                                            
                  'user-agent' => [
                                                                            
                                    'Mojolicious (Perl)'
                                                                            
                                  ]
                                                                            
                }
                                                                            
 }, 'Mojo::Headers' )
                                                       }, 
'Mojo::Content::MultiPart' ),
                                   'url' => bless( {
                                                     'host' => 
'www.googleapis.com',
                                                     'path' => bless( {
                                                                        
'path' => '/batch/gmail/v1'
                                                                      }, 
'Mojo::Path' ),
                                                     'scheme' => 'https'
                                                   }, 'Mojo::URL' )
                                 }, 'Mojo::Message::Request' )
               }, 'Mojo::Transaction::HTTP' );

This object gets called with 
my $res = $self->ua->start($tx)->res;

The $res contains the 400 error from google with no explanation.


On Tuesday, September 18, 2018 at 12:45:42 AM UTC-4, Dan Book wrote:
>
> You want the multipart content generator. Scroll down to the very last 
> example in https://metacpan.org/pod/Mojo::UserAgent::Transactor#tx
>
> -Dan
>
> On Mon, Sep 17, 2018 at 10:22 PM Steve Dondley <[email protected] 
> <javascript:>> wrote:
>
>> I'm trying to hack a perl module that uses mojolicious to make api calls 
>> to google's api so that it can make batch api call as documented here: 
>> https://developers.google.com/gmail/api/guides/batch
>>
>> I've made various attempts but no calls are resulting in a successful 
>> response. Here's what I'm currently trying.
>>
>>       my $options =
>>           [
>>             {
>>               content => 'GET /gmail/v1/users/
>> [email protected]/messages/165e91c27e4af0be',
>>               'Content-Type' => 'application/http',
>>             },
>>             {
>>               content => 'GET /gmail/v1/users/
>> [email protected]/messages/165e94ce49900df2',
>>               'Content-Type' => 'application/http',
>>             }
>>           ];
>>
>>
>>       my $path = 'https://www.googleapis.com/batch/' . $s->api . '/' . $s
>> ->version;
>>
>>
>>       my $headers = {'Authorization' => 'Bearer TOKEN_HERE'};
>>
>>
>>
>>
>>       $tx = $self->ua->build_tx(
>>             uc $http_method => $path => $headers => json => 
>> $optional_data );
>>
>>
>>
>>
>> This results in a tranaction object that looks like this:
>>
>>
>> $VAR1 = bless( {
>>                  'req' => bless( {
>>                                    'content' => bless( {
>>                                                          'headers' => 
>> bless( {
>>                                                                           
>>      'headers' => {
>>                                                                           
>>                     'content-type' => [
>>                                                                           
>>                                         'application/json'
>>                                                                           
>>                                       ],
>>                                                                           
>>                     'authorization' => [
>>                                                                           
>>                                          'Bearer TOKEN_HERE'
>>                                                                           
>>                                        ],
>>                                                                           
>>                     'accept-encoding' => [
>>                                                                           
>>                                            'gzip'
>>                                                                           
>>                                          ],
>>                                                                           
>>                     'user-agent' => [
>>                                                                           
>>                                       'Mojolicious (Perl)'
>>                                                                           
>>                                     ]
>>                                                                           
>>                   }
>>                                                                           
>>    }, 'Mojo::Headers' ),
>>                                                          'events' => {
>>                                                                        
>> 'read' => [
>>                                                                           
>>          sub { "DUMMY" }
>>                                                                           
>>        ]
>>                                                                      },
>>                                                          'read' => $VAR1
>> ->{'req'}{'content'}{'events'}{'read'}[0],
>>                                                          'asset' => bless
>> ( {
>>                                                                           
>>    'content' => '[{"Content-Type":"application\\/http","content":"GET 
>> \\/gmail\\/v1\\/u
>> sers\\/[email protected] 
>> <javascript:>\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
>>  
>> \\/gmail\\/v1\\/users\\/[email protected]\\/messag
>> es\\/165e94ce49900df2"}]'
>>                                                                           
>>  }, 'Mojo::Asset::Memory' )
>>                                                        }, 
>> 'Mojo::Content::Single' ),
>>                                    'url' => bless( {
>>                                                      'scheme' => 'https',
>>                                                      'host' => '
>> www.googleapis.com',
>>                                                      'path' => bless( {
>>                                                                         
>> 'path' => '/batch/gmail/v1'
>>                                                                       }, 
>> 'Mojo::Path' )
>>                                                    }, 'Mojo::URL' ),
>>                                    'method' => 'POST'
>>                                  }, 'Mojo::Message::Request' )
>>                }, 'Mojo::Transaction::HTTP' );
>>
>>
>>
>> Trying anything other than json for the generator results in an error:
>>  Use of uninitialized value $cb in method lookup
>>
>> Fiddling with the content type settings doesn't help make this go away.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Mojolicious" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to