Google APi ruby โโclient
I have a way to create a folder on google drive as soon as the create method is created. I want the folder to be created after saving the batch. Below is the code using Im. See the below redirect method page as soon as it is resolved. So the desktop query
def create
client = Signet::OAuth2::Client.new(
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
:token_credential_uri => 'https://www.googleapis.com/oauth2/v3/token',
:client_id => "XXXXXX-XXXXXX",
:client_secret => "XXXXXX-XXX",
:scope => 'https://www.googleapis.com/auth/drive',
:redirect_uri => "http://localhost:3000/batches/"
)
@batch = Batch.new(params[:batch])
respond_to do |format|
if @batch.save
if params[:code].present?
client.code = request['code']
client.fetch_access_token!
x = Google::Apis::DriveV3::DriveService.new
x.authorization = client
files = x.list_files(options: { authorization: client })
file_metadata = {
name: 'Batches-new',
mime_type: 'application/vnd.google-apps.folder',
}
file = x.create_file(file_metadata, fields: 'id')
Rails.logger.debug "Folder Id: #{file.id}"
else
format.html {redirect_to client.authorization_uri.to_s}
end
format.html {redirect_to batches_path(trek_id: @batch.trek_id), notice: 'Batch was successfully created.' }
format.json { render json: @batch, status: :created, location: @batch }
else
format.html {
flash.now[:error] = @batch.errors.full_messages
render action: "new"
}
format.json { render json: @batch.errors, status: :unprocessable_entity }
end
end
end
after the index page is moved on the create action page without creating a folder. How to create a folder is created before going to the index page. Thanx in advance.
+3
source to share
No one has answered this question yet
Check out similar questions: