Ruby google_drive gem Problems - ruby

https://github.com/gimite/google-drive-ruby
There seems to be an update on google docs. There is now an "Addon" function in NEW google docs. Has someone found a work around for new version of google docs and google_drive gem?
require 'google_drive'
session = GoogleDrive.login("username#gmail.com", "password")
# the key is found in the url of a google doc web address
# https://docs.google.com/a/pz7XtlQC-PYx-jrVMJErTcg#gid=0
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
ws.rows
=> ERRORS
ws[1,1]
=> "test"
ws[1,1] = "hi"
ws.save()
=> ERRORS
does anyone have a workaround?

From the version 0.3.8 gem supports new Spreadsheets.
Also, you can try spreadsheer_by_url method.
For example:
require 'google_drive'
session = GoogleDrive.login("username#gmail.com", "password")
ws = session.spreadsheet_by_url('https://docs.google.com/a/pz7XtlQC-PYx-jrVMJErTcg#gid=0').worksheets[0]

Related

Customize Instagram widget on a Dashing.io dashboard

I have set up a dashboard using dashing with a number of (mostly) existing widgets. That worked so far - see production dashboard here (work in progress).
Now I would like to have an Instagram widget that displays the n lastest images taken by username.
I have found a widget that will display images by long and lat and also was able to get my tokens configured, so I can talk to the Instagram API.
Here's the code of my current widget originally from #mjamieson's gist on github.
require 'instagram'
require 'rest-client'
require 'json'
# Instagram Client ID from http://instagram.com/developer
Instagram.configure do |config|
config.client_id = ENV['INSTAGRAM_CLIENT_ID']
config.client_secret = ENV['INSTAGRAM_CLIENT_SECRET']
end
# Latitude, Longitude for location
instadash_location_lat = '45.429522'
instadash_location_long = '-75.689613'
SCHEDULER.every '10m', :first_in => 0 do |job|
photos = Instagram.media_search(instadash_location_lat,instadash_location_long)
if photos
photos.map do |photo|
{ photo: "#{photo.images.low_resolution.url}" }
end
end
send_event('instadash', photos: photos)
end
I got this to work, but would like to modify the given API call to only display images taken by me / a user of my choice. Unfortunately I don't understand ruby or json enough to figure out what the Instagram API documentation wants me to do.
I found the following url
https://api.instagram.com/v1/users/{user-id}/media/recent/?access_token={acces-token}
and tried it (with my credentials filled in). It returned json data correctly including my images (among other data).
How can I modify the given code to display images by username instead of location?
Any help is greatly appreciated.
You'll need an access_token to get content from some user. Take a look at sample application on gem page.
It seems you need something like this:
# here we take access token from session, assuming you already got it
# sometime before and stored it there for future use
client = Instagram.client(:access_token => session[:access_token])
photos = client.user_recent_media
And this example how to get this access_token using OAuth2 browser authorization and sinatra app:
require "sinatra"
require "instagram"
enable :sessions
CALLBACK_URL = "http://localhost:4567/oauth/callback"
Instagram.configure do |config|
config.client_id = "YOUR_CLIENT_ID"
config.client_secret = "YOUR_CLIENT_SECRET"
# For secured endpoints only
#config.client_ips = '<Comma separated list of IPs>'
end
get "/" do
'Connect with Instagram'
end
get "/oauth/connect" do
redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
end
get "/oauth/callback" do
response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
session[:access_token] = response.access_token
redirect "/nav"
end
Solution
require 'sinatra'
require 'instagram'
# Instagram Client ID from http://instagram.com/developer
Instagram.configure do |config|
config.client_id = ENV['INSTAGRAM_CLIENT_ID']
config.client_secret = ENV['INSTAGRAM_CLIENT_SECRET']
config.access_token = ENV['INSTAGRAM_ACCESS_TOKEN']
end
user_id = ENV['INSTAGRAM_USER_ID']
SCHEDULER.every '2m', :first_in => 0 do |job|
photos = Instagram.user_recent_media("#{user_id}")
if photos
photos.map! do |photo|
{ photo: "#{photo.images.low_resolution.url}" }
end
end
send_event('instadash', photos: photos)
end
Explaination
1.) In addition to the client_id and client_secret I had defined before, I just needed to add my access_token to the Instagram.configure section.
2.) The SCHEDULER was correctly working, but needed to call Instagram.user_recent_media("#{user_id}") instead of Instagram.media_search(instadash_location_lat,instadash_location_long)
3.) To do that I had to set a second missing variable for user_id
Now the call gets recent media filtered by user ID and outputs it into the dashing widget.
Thanks for the participation and hints! That pointed me into the right direction of the documentation and helped me to figure it out myself.

Getting Twitter rate limit information

I am using the Twitter Gem to perform some searches using Twitter's 1.1 API and I'd like to get some examples on how to query my current rate limit information.
I've found the class documentation but it's not clear to me how to query this info. I have done the following :
#!/usr/bin/env ruby
require 'twitter'
client = Twitter::REST::Client.new do |config|
#... omitting connection info ....
end
rate_info = Twitter::RateLimit.new
tweets = client.search('obama -rt', lang: 'en', result_type: 'recent').take(3)
# Do stuff with tweets
puts "Limit is #{rate_info.limit}"
but the "rate_info.limit" is null; I would think I need to somehow "link" my client object to the RateLimit object. How can I best query this info using the Twitter Gem?

Twitter REST API and ruby hashtag confusion

so I'm trying to set up a script to grab tweets so I can use them in my app. Currently I'm using Ruby 2.0.0 and the 1.1 Twitter API REST. Currently I'm not worried about storing the tweets in a database or anything I'm just simply trying to get the correct tweets into terminal. Here is my current code.
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "XXXXXXXXXXXXXXXXXX"
config.consumer_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
config.access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
config.access_token_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
end
topics = ["#BreakingBad", "#Gameofthones"]
client.filter(:track => topics.join(",")) do |tweet|
puts tweet.text
endtag = options[:search]
My problem is that when I run the script I get flooded with just a mass of tweets in all different languages. Any help would be great. Thanks.

Ruby Gem Twitter - Twitter::Error::ClientError: initialize: name or service not known

I want to use the ruby gem 'twitter' but for an unknown reason it does not work.
Here's the error I get when running the script:
C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/faraday-0.8.6/lib/faraday/reques/multipart.rb:5 warning: already initialized constant DEFAULT_BOUNDARY
Twitter::Error::ClientError: initialize: name or service not known
request at C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/twitter-4.5.0/lib/twitter/client.rb:85
get at C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/twitter-4.5.0/lib/twitter/client.rb:64
__send__ at org/jruby/RubyBasicObject.java:1671
send at org/jruby/RubyKernel.java:2094
cursor_from_response at C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/twitter-4.5.0/lib/twitter/api/utils.rb:108
cursor_from_response_with_user at C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/twitter-4.5.0/lib/twitter/api/utils.rb:96
friends at C:/nwcloud/jruby-1.7.2/lib/ruby/gems/shared/gems/twitter-4.5.0/lib/twitter/api/friends_and_followers.rb:314
(root) at tCon.rb:11
I registered my application in my twitter developer account and installed the gem.
Here's my coding (I removed all keys):
require 'twitter'
client = Twitter::Client.new(
:consumer_key => "",
:consumer_secret => "",
:oauth_token => "",
:oauth_token_secret => ""
)
client.update("I'm tweeting with #gem!")`
I also tried just to do it like this:
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
.. it doesn't work :-( .. I'm a newbie to ruby so perhaps I forgot sth...
I'm really looking forward to your answers. Thank you in advance!!!
I think it was a proxy problem. After deploying it to the cloud it worked!

[Twitter4R]Twitter::ForbiddenError

I'm new to Twitter4R and Ruby on Rails. I'm using Ruby 1.9.2, Rails 3.1 and Twitter4R v0.7.0.
I'm trying to get my friends list from Twitter.
twitter = Twitter::Client.new(oauth_access: { key: token, secret: token_secret})
#these lines works fine.
twitter.status(:post, "POST TEST!!!")
twitter.friend(:add, "xxxx_jp")
#this line will cause ForbiddenError
friends = twitter.my(:friends)
I've checked the following site for information.
http://twitter4r.rubyforge.org/rdoc/Twitter/Client.html
Update
I now added config/initializers/twitter4r.rb:
require 'twitter'
Twitter::Client.configure do |config|
config.oauth_consumer_token = consumer_key
config.oauth_consumer_secret = consumer_secret
end
When debugging, I see the consumer_key and consumer_secret in Twitter::Consumer on debug window. But methods that require authentication like my(:friends) do not work.
How do I avoid the ForbiddenError?
That looks like the authentication in Twitter::Client.new didn't actually work. Here's a presentation on OAuth by Twitter4R's creator Susan Potter:
http://www.slideshare.net/mbbx6spp/twitter4r-oauth

Resources