Is there a way Facebook Test User posts with privacy EVERYONE? - ruby-on-rails

I am writing automated tests for Facebook integration with Facebook Test users feature: https://developers.facebook.com/docs/apps/test-users
And I need to test that post is public, but cannot make that because when I set post privacy value to EVERYONE, it sets it to ALL_FRIENDS and in response I get:
{
"success" => true
}
I am using Ruby gem Koala, my code looks like this:
#test_users = Koala::Facebook::TestUsers.new(:app_id => ENV['FACEBOOK_KEY'], :secret => ENV["FACEBOOK_SECRET"])
fb_data = #test_users.create(true, "user_posts,publish_actions")
graph = get_graph(fb_data["access_token"])
graph.put_object("/", "/#{post_id}", privacy: {value: "EVERYONE"}.to_json)
It may be unclear, but graph variable contains test user created access_token

Related

what is Instagram API basic access in sandbox?

I try to use instagram API in sandbox.
I use Ruby with gem 'instagram'
But I can only call method
Instagram.user_recent_media( {:count => 5})
def user_recent_media(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
id = args.first || "self"
response = get("users/#{id}/media/recent", options)
response
end
like #instagram = Instagram.user_recent_media( {:count => 5})
I try to call other method like
def follow_user(id, options={})
options["action"] = "follow"
response = post("users/#{id}/relationship", options, signature=true)
response
end
get
Instagram::BadRequest in HomeController#index
GET
https://api.instagram.com/v1/users/[user_ID]/follows.json?access_token=[Access_token]&max_id=10:
400: This request requires scope=follower_list, but this access token
is not authorized with this scope. The user must re-authorize your
application with scope=follower_list to be granted this permissions.
Is there any method I can use ??
instagram-ruby-gem API
Basically, you have to register your application with Instagram here and hope they accept it. There isn't a way around this.
Here's a little reading on how they basically said "buzz off" to third party app developers http://www.businessinsider.com/instagram-made-a-change-that-stopped-lots-of-third-party-apps-from-working-2016-6

Unable to get facebook Open Graph action approved using rails and the Koala gem

I keep getting this message after submitting my application
Your Open Graph action failed to publish on any of the Platforms you submitted. Make sure the action is working properly by publishing the action with a test user before resubmitting.
I have testers with test users, my own account, testers and it works all the time..
background.
users has_many :authorization_providers, e.g. facebook, twitter, gplus e.t.c
in the facebook action I'm fetching the oauth_token
def facebook
begin provider = authorization_providers.where(provider: 'facebook').first
#facebook ||= Koala::Facebook::API.new(provider.oauth_token)
block_given? ? yield(#facebook) : #facebook
rescue Koala::Facebook::APIError => e #Koala::Facebook::APIError
return nil
end
#facebook
end
In this action I'm getting permission
def facebook_publish_actions
if facebook
begin
permissions = facebook.get_connection("me", "permissions")
publish_actions_permission = permissions.find { |permission| permission["permission"] == "publish_actions" }
publish_actions_permission_granted = publish_actions_permission && publish_actions_permission["status"] == "granted"
return publish_actions_permission_granted
rescue
return false
end
else
return false
end
end
The actual posting is done from a sidekiq worker where 'share_on_facebook' and 'recording' is records from the db
user.facebook.put_wall_post(share_on_facebook.message,
{
"name" => "#{recording.title}",
"link" => "http://www.digiramp.com/users/#{recording.user.slug}/recordings/#{recording.id}",
"caption" => "#{user.name} recomended a recording",
"description" => "#{recording.comment}",
"picture" => "#{recording.get_artwork}"
})
On the facebook developer page I have created one story for the app 'Recommend a Song'
All the above works.
Anyone willing to help me I will grant all the required permissions.
Right now you can go to http://digiramp.com and sign up with facebook.
I will add you as a tester to my project and you should be able to post.
Edit:
I Do pass the id: FbRecordingCommentWorker.perform_async(#share_on_facebook.id)
Can you post the line of the code, where you initiate sidekiq job? Using objects in sidekiq call may not work as expected as objects are stored in hash representation in Redis. So better idea is replacing the object parameters to values.
Replacing some thing like this
User.delay.do_some_stuff(current_user, 20)
with
User.delay.do_some_stuff(current_user.id, 20)
and finding user object in the actual method may fix the issue.

Can't get Google Analytics user data to show in Rails app

I'm attempting a server-to-server connection between my Google Analytics account and my Rails app. For this, I'm using the Legato, omniauth-google-oauth2, and google-api-client gems. My intention is to have a rake task that sieves out pageview data from a particular site. However, I can't seem to get any user data out of it. Here's the code:
require 'google/api_client'
def service_account_user(scope="https://www.googleapis.com/auth/analytics.readonly")
client = Google::APIClient.new(
:application_name => "Listmaker",
:application_version => "2.0"
)
key = OpenSSL::PKey::RSA.new(Figaro.env.google_private_key, "notasecret")
service_account = Google::APIClient::JWTAsserter.new(Figaro.env.google_app_email_address, scope, key)
client.authorization = service_account.authorize
oauth_client = OAuth2::Client.new("", "", {
:authorize_url => 'https://accounts.google.com/o/oauth2/auth',
:token_url => 'https://accounts.google.com/o/oauth2/token'
})
token = OAuth2::AccessToken.new(oauth_client, client.authorization.access_token)
Legato::User.new(token)
end
class Pageviews
extend Legato::Model
metrics :pageviews
dimensions :page_path
filter :for_page_path, &lambda {|page_path| matches(:page_path, page_path)}
end
puts profile = service_account_user.profiles.first
I appear to be getting an empty array for the profile variable after running the task. I've definitely added the developer email address to the Google Analytics View I'm interested in. Not sure what's wrong.
For a service account to work with Google Analytics the Service account email must be added at the Account level. It wont work if it was only added at the view level.

Error Creating Shopify Webhook through the API

I am trying to create a Webhook through the API.
When the Customer installs the app (Controller):
def init_webhooks
topics = ["products/create", "products/update", "products/delete"]
topics.each do |topic|
webhook = ShopifyAPI::Webhook.create(format: "json", topic: topic, address: "http://#{#current_host}/webhooks/#{topic}")
raise "Webhook invalid: (#{topic}) #{webhook.errors}" unless webhook.valid?
end
end
Here is the error from the log:
RuntimeError (Webhook invalid: (products/create) #<ActiveResource::Errors:0x00000003bd7358>):
EDIT:
I have even tried just creating one webhook without the block code like so:
webhook = ShopifyAPI::Webhook.create topic: "products/create", address: "http://myapp.com/webhooks/products/create", format: "json"
But I get the same thing.
From my Routes file:
match 'webhooks/products/create' => 'webhook#product_new'
match 'webhooks/products/update' => 'webhook#product_updated'
match 'webhooks/products/delete' => 'webhook#product_deleted'
I know that the authorization and shop is in fact installing correctly because if I Comment out the 'Raise' error line, I then proceed to the index page which displays some test orders and test products that I created within the Shopify Admin.
I'm not sure where to go from here. Thanks
b
The params you use (topic,format,address) look good to me, but shouldn't it be ShopifyAPI::Webhook.new instead of create?
Did you now there is a shopify console where you can easily test your ruby code?

Ruby OAuth Nightmare: Using Contacts API

I've been spending the last few days banging my head against the wall on supporting the ability to add a contact to the Google Contacts API in my Rails 3 application. Despite many false starts, I've finally made some progress by employing the Ruby OAuth gem, and following the tutorial here: http://everburning.com/news/google-analytics-oauth-and-ruby-oh-my/
When I follow this in the console, I get further than I do in my Rails app. I can create an access token, authenticate against Google's service with the specific scope of the Contacts API, and apply the oauth_verifier token to get an access token. But when it comes time to push the data, I get this error:
response = at.post("https://www.google.com/m8/feeds/contacts/default/full", gdata)
=> #<Net::HTTPUnauthorized 401 Unknown authorization header readbody=true>
Where does the "readbody=true" header come from, and how would I get rid of it?
But it's worse in the Rails app. I have one controller action ("googlecontacts") that creates the request token and leads the user to the authentication site with Google:
def googlecontacts
#card = Card.find_by_short_link(params[:id])
#consumer = OAuth::Consumer.new(
'anonymous',
'anonymous',
{
:site => 'https://www.google.com',
:request_token_path => '/accounts/OAuthGetRequestToken',
:access_token_path => '/accounts/OAuthGetAccessToken',
:authorize_path => '/accounts/OAuthAuthorizeToken',
:signature_method => 'HMAC-SHA1',
:oauth_version => '1.0'
})
#request_token = #consumer.get_request_token(
{:oauth_callback => 'http://monkey.dev/cards/google_auth?redir='+#card.short_link},
{:scope => "https://www.google.com/m8/feeds/"}
)
session[:request_token] = #request_token
redirect_to #request_token.authorize_url
end
This appears to work; I get a working request token object, and the user is forwarded to the Google service to authenticate. The callback URL ("google_auth") should take the oauth_verifier token to create an access token. Here's the beginning of the controller:
def google_auth
#access_token = session[:request_token].get_access_token(:oauth_verifier=>params[:oauth_verifier])
And here's where it craps out. The error on that last line is:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
But the values that are in there -- the session[:request_token] and the params[:oauth_verifier] -- are present and accounted for in that action! I can't figure out what is nil here.
So I guess I need to figure out this second problem first, but bonus points for answering the first problem as well. :-)
Thanks for reading.
Aaron.
Try setting/getting the session data with a string not symbol, i.e. session["request_token"], not session[:request_token]. I know I've had that issue before in the past.
Unknown authorization header typically means that your signature didn't match what you sent. I do not recommend the oauth gem. It's full of bugs and weird issues and it doesn't properly escape certain parameters.
The Signet gem is the officially supported gem for accessing Google APIs in Ruby.
Here's how you'd implement this with Signet:
require 'signet/oauth_1/client'
require 'addressable/uri'
card = Card.find_by_short_link(params[:id])
callback = Addressable::URI.parse('http://monkey.dev/cards/google_auth')
callback.query_values = {'redir' => card.short_link}
client = Signet::OAuth1::Client.new(
:temporary_credential_uri =>
'https://www.google.com/accounts/OAuthGetRequestToken',
:authorization_uri =>
'https://www.google.com/accounts/OAuthAuthorizeToken',
:token_credential_uri =>
'https://www.google.com/accounts/OAuthGetAccessToken',
:client_credential_key => 'anonymous',
:client_credential_secret => 'anonymous',
:callback => callback
)
session[:temporary_credential] = (
client.fetch_temporary_credential!(:additional_parameters => {
:scope => 'https://www.google.com/m8/feeds/'
})
)
redirect_to(client.authorization_uri)

Resources