mschilli / net-google-drive-simple

Net::Google::Drive::Simple CPAN Module
Other
11 stars 22 forks source link

Feature request: share a file #30

Open zezzagio opened 5 years ago

zezzagio commented 5 years ago

This module is actually the simplest one I've found to access Google Drive, yet providing almost all I need... except, for what I can see, a method for sharing a file.

I tried something like this, and it works for my need; it would be better, though, having this as a native feature (possibly with a better, more robust implementation than mine):

package Net::Google::Drive::Simple;

sub file_share {

my( $self, $file_id ) = @_;

my $url = URI->new( $self->{ api_file_url } . '/' . $file_id . '/permissions' );

my $data = $self->http_json( $url, {
file_id => $file_id,
    type    => 'anyone',
    role  => 'reader',
    withLink  => 'true'
} );

if( ! defined $data ) {
    return undef;
}

my $metadata = $self->file_metadata($file_id);

return $metadata->{webContentLink};

}