How to upload video to YouTube via Ruby? - ruby

I need to upload video files from my computer to youtube automatically, I use ruby.
I tried gem youtube_it - I have error YouTubeIt::AuthenticationError: BadAuthentication - my actions:
client = YouTubeIt::Client.new(:username => "email#gmail.com", :password => "my_passwd", :dev_key => "developer_key")
client.video_upload(File.open("file_from_drive"), :title => "test",:description => 'test')
Also I tested manually upload video from my email#gmail.com my_passwd Google account - I works well. Dev_key I got here - http://code.google.com/apis/youtube/dashboard
Then I tried gem gdata as here - How to upload video on YouTube with Ruby
require 'gdata'
yt = GData::Client::YouTube.new
yt.clientlogin("email#gmail.com", "my_passwd")
It raises error
GData::Client::AuthorizationError: request error 403: Error=BadAuthentication
Info=WebLoginRequired
So, How should I automatically upload video? Maybe problem is in my google account?

Related

how to use TwitterAPI v1.1 to upload an image in s3?

I am developing web app using laravel and s3
I just wanna upload an image to twitter server like this https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload
why I cannot upload and how can I solve this.
Thank you.
I am absolutely sure that there is the image in s3 to see
dd($result['ObjectURL']);
I've tried these
$twitter = new TwitterOAuth(
'consumer_key',
'consumer_secret',
'access_token',
'access_secret',
);
$s3FilePath is like "https://buket_name.s3・・・"
$media = $twitter->upload('media/upload',['media' => $s3FilePath]);
//could not upload."You must supply a readable file"

Rails Active Storage : video_tag not showing video

I m trying to implement some upload then play video in my app using Rails 5.2.3 and Active Storage. After fighting with active storage for a while i m finally sure that my attachment is containing the file i want to attach => after inspecting the src is correct
The problem here is that i keep getting those warnings from firefox console :
HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHM…JibG9iX2lkIn19--a44730f58a07282f626737b6a541d57fa9dc11c4/vid failed. 23
Cannot play media. No decoders for requested formats: text/html
and a video area with the following message "
No video with supported format and MIME type found"
Now, the console warnings are only showing up in Firefox but the video isn't playable in all the browsers that i tested so i think that my problem got something to do with the warning. I m new to rails so i ve tried all what i have found in google without solving my problem.
I m showing the video with the video_tag this way :
<%= video_tag(url_for(#play.clip), style: "width:100%;height:auto", :controls => true) if #play.clip.attached? %>
And added a meme_types.rb in initializers with the following code
Rack::Mime::MIME_TYPES.merge!({
".mp4" => "video/mp4",
})
I have tried to display the video using plain html5 ( which is the same) and i m naturally getting the same warnings...
fixed. The issue wasn't coming from the active storage itself. The get request to play the video was stopped by a line i wrote in routes.rb to make all "unknown routes" redirect to root_path :
get '*path' => redirect('/')
Now t hat the video playing video has been fixed i have to deal with "redirecting unknown paths to root without causing a problem with the GET "

Upload Facebook profile image with Carrierwave

I'm trying to use the Facebook profile image with Devise, uploading it to S3 with CarrierWave / fog, but the link I'm getting from Facebook provided in auth.info.image is a link to download the file, not an image that CarrierWave can use.
If you go to the link in a browser, it is a file download link. I've not seen any articles anywhere that address this. I thought I could use CarrierWave to download the file to /tmp, then upload it, but calls to CarrierWave::Uploader::Download do not work. Or I've seen other articles explaining that you can save the link provided by Facebook just use that in an = image_tag but that doesn't work, either.
In my User model:
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create! do |user|
user.email = auth.info.email
user.provider = auth.provider
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.uid = auth.uid
user.password = Devise.friendly_token[0, 20]
user.password_confirmation = user.password
user.profile_image = auth.info.image
end
end
but user.profile_image is nil. I have no problem with CarrierWave - I've used it on several other projects to save to AWS with fog.
I would like to either a) save a link to the image that I can use in a Rails view, but as mentioned already, I do not have that - the link returned by Facebook is a link to download an image, so, b) is to download the file, save the filename to the User model and upload the file to AWS.
Use "#{auth.info.image}?type=large" instead of auth.info.image
Apparently CarrierWave has its own magic, whereby if you prepend the field name with remote_ and append it with _url it knows to download a file before uploading. So, my field name is profile_image, and (in my User model) self.from_omniauth(auth) method:
user.remote_profile_image_url = auth.info.image
just works. The field name has the correct filename saved to it, and the files (full size and thumbnail) are uploaded to S3.

How can I upload paperclip image on remote server (accessed by pem file) rails console?

I am having production server and database is from aws. I visit remote machine using pem file & start rails console.
I have particular invitee (from Invitee model) & have following column to store image using paperclip
invitee.rb
has_attached_file :profile_pic, {:styles => {:large => "640x640>",
:small => "200x200>",
:thumb => "60x60>"},
:convert_options => {:large => "-strip -quality 90",
:small => "-strip -quality 80",
:thumb => "-strip -quality 80"}
}.merge(INVITEE_IMAGE_PATH)
I want to upload image at https://imgur.com/9a6UzVx by using rails console production. How can I do this?
Input I can have is, image url and object of invitee for which profile_pic columns to be updated.
I have image in my local machine but I cannot upload it from local to remote so using https://imglur.com
I suggest you to check another answer "Save image from URL by paperclip
" which does what you want to achieve. Check code snippet: self.profile_pic = open(url) will upload the picture to your model. Your picture real URL is https://i.imgur.com/9a6UzVx.png

Download my own private albums using Flickr API

I'm trying to download my own flickr albums using the API. I'm using the flickr.rb gem here
I am creating a new object using this:
#flickr = Flickr.new({api_key: 'xxxxx', shared_secret: 'xxxxx', verify_ssl: false})
And then I'm using:
p = #flickr.photoset(photoset_id)
Where I pass the id of my photoset I want to download.
I keep getting the error:
/.rvm/gems/ruby-2.2.5/gems/flickr.rb-1.2.1/lib/flickr.rb:199:in `request': Photoset not found (RuntimeError)
What is the correct way to authenticate to Flickr and download my photos? I don't want to build any UI, just want a command line app to do this. Is there some URL I need to hit in the browser to authorize the app and grant permissions? The documentation is really sparse and doesn't give any examples.
Update: In response to #r-f-nelson
The 'user' as retrieved:
#Flickr::User:0x007fd8cea6ad98 #id="29916617#N02", #username="taraporefarhad", #client=#<Flickr:0x007fd8cf09fc68 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=false, #api_key="36705xxxxxxxxxxxxxxx", #shared_secret="xxxxxxxxxxxxxx", #auth_token=nil, #ca_file=nil
The 'flickr' client object:
#Flickr:0x007fd8cf09fc68 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=false, #api_key="36705xxxxxxxxxxxxxxx", #shared_secret="xxxxxxxxxxxxxx", #auth_token=nil, #ca_file=nil, #user=#
Flickr::User:0x007fd8cea6ad98 #id="29916617#N02", #username="taraporefarhad", #client=#<Flickr:0x007fd8cf09fc68 ...
The Photoset object:
#Flickr::Photoset:0x007fd8cf06c9d0 #id="72157638843727066", #api_key=nil, #client=#<Flickr:0x007fd8cf06c8b8 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=true, #api_key=nil, #shared_secret=nil, #auth_token=nil, #ca_file=nil
/.rvm/gems/ruby-2.2.5/gems/flickr.rb-1.2.1/lib/flickr.rb:199:in `request': Invalid API Key (Key has invalid format) (RuntimeError)
Note above that the "photoset" object has a different flickr client object id and NO shared secret and API key! Not sure how that's happening since I'm using the same client and user objects to get the photoset as well.
Assuming you are successfully connecting to Flickr's API, you can browse your own photosets like so:
user = flickr.users('you#yourflickraccount.com')
photosets = user.photosets
From there you can iterate through your photosets to find the correct one. I'm guessing whatever id you're using is not the actual photoset_id that the Flickr API uses.

Resources