KOALA + FACEBOOK GRAPH gives FARADAY error (ConnectionFailed - Connection Refused - connect(2)) - ruby-on-rails

I am using koala(1.3.0) with rails (3.0.7).
This is how I use them.
Link to click function of facebook
<%= link_to 'Facebook Login', Koala::Facebook::OAuth.new.url_for_oauth_code(:callback => facebook_redirect_url), :class => "facebook_login" %>
This goes to following link
https://graph.facebook.com/oauth/authorize?client_id=MY_APP_ID&redirect_uri=http%3A%2F%2Fexample.example.com%2Ffacebook%2Fredirect
Now I get the code in params in my facebook controller of redirect.
Following is what I do next in redirect method of facebook controller.
session[:access_token] = Koala::Facebook::OAuth.new(url_r).get_access_token(params[:code]) if params[:code]
but this line of code gives faraday ConnectionFailed error.
I am stuck at this point. Can't figure out what is the reason behind this.
I have also done the following with this another way also.
After I get code in params
facebook_access_token_redirect_link = "https://graph.facebook.com/oauth/access_token?client_id=355***************&redirect_uri=#{url_i}&client_secret=MY_APP_SECRET&code=#{params[:code]}"
and redirect to this link. But then I get an error from facebook
Error validating verification code
I don't understand this also.
Any help regarding this is appreciated.
Thanks.

It was a silly thing. The server I was hosting my app at has banned all https connections.
Removed that restriction and I got koala working.

Related

Wrong redirect URI using shopify-app gem

I've been trying to create an application these past few days. First I've been trying to create an app on localhost (http://localhost) but have been getting errors since Shopify is only supporting https. Then I deployed the application to my VPS (https://my.domain.com) and have specified the callback-URL in my partners account as well (https://my.domain.com). When I enter the shop where I want to install my application the installation window pops up and I can click on "Install". If I do so, the same mismatch occurs. I figured out it was because the URL looks like this:
https://shop.myshopify.com/admin/oauth/authorize?client_id=XXX&redirect_uri=HTTP%3A%2F%2Flocalhost%3...
This is where the mismatch happens. I do not understand why because the redirect_uri should be the callback-URL by default, if not specified otherwise. The callback-app-URL is "https://my.domain.com" so why is the redirect_uri "http://..." and how can I fix this?
I suppose I need to specify the redirect_uri somewhere in my omniauth.rb initializer?
provider :shopify, redirect_uri: "https://localhost:3000"
ShopifyApp.configuration.api_key,
ShopifyApp.configuration.secret,
:scope => ShopifyApp.configuration.scope,
:setup => lambda {|env|
params = Rack::Utils.parse_query(env['QUERY_STRING'])
site_url = "https://#{params['shop']}"
env['omniauth.strategy'].options[:client_options][:site] = site_url
}
Any help is appreciated, really don't know what to do

Koala::Facebook::ClientError Exception: type: GraphMethodException, code: 100, message: Unsupported get request

I did research on this issue, however, nothing worked for me.
I am using Facebook Realtime subscription and graph API to track my facebook page (using page token).
When a user posts a photo/video I am getting following data pushed by fb to my server:
{"field"=>"feed",
"value"=>
{"item"=>"photo",
"verb"=>"add",
"photo_id"=>302522856593533,
"post_id"=>"824413870916335_302522856593533",
"sender_id"=>100005074631221}}
When I use post_id (824413870916335_302522856593533) to make call to graph API for fetching details of the post, I am encountering following error:
*** Koala::Facebook::ClientError Exception: type: GraphMethodException, code: 100, message: Unsupported get request.
Please read the Graph API documentation at
https://developers.facebook.com/docs/graph-api [HTTP 400]
However, if user posts without photo/video, I am able to get post details successfully. In case, admin posts photo/video, I am able to get details of that post too.
I am sure about the correctness of page token and code. I think, there must be something related to settings.
I have multiple pages to fetch. Tested with both of these methods Koala wiki provides
#graph = Koala::Facebook::GraphAPI.new # pre 1.2beta
#graph = Koala::Facebook::API.new # 1.2beta and beyond
Some pages have ids and some have not in their uris so in a page like this:
https://www.facebook.com/pages/Istanbul-Kuafor/241559912664906
fc.get_object("Istanbul-Kuafor")
gives me the error message you mentioned so I use
fc.get_object("241559912664906")
if page doesn't have an id(some pages don't, somehow), I use the page name and it works this time.

Google Analytic with grub gives me 404 error.

I am beginner to ror development.I am developing small RoR application in which i want to integrate Google analytic. I am using Garb gem for thid
According to gem I used
Garb::Session.login(username, password)// for initial session setup
after that select proper profile
profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == 'UA-XXXXXXX-X'}
but when I tried to get the data it gives me error
Exits.results(profile, :filters => {:page_path.eql => '/'})
// error
Error 404 (Not Found)!!1
The requested URL /analytics/feeds/accounts/default was not found on this server.
How to solve this problem is there any way to handle this situation. Or whether I am doind something wrong?
Need Help.... Thank you.....

Koala fails to perform put_connections as a page

I have a ruby on rails app that uses Koala to integrate with facebook.
I use Put_connections to post a GraphAPI action and object to facebook.
Share on wall works perfect using a line like this
Thread.new {
#graph.put_connections("me", "MyApp:MyAction", :MyObject=> url_for(#myobject), :image=> image_location)
}
also posting a simple message as the page works perfectly using
#page_graph.put_object('mypage-id', 'feed', :message => 'This is posted as the page 2')
However when i try to post the graphApi action as the page, nothing happens. using the following lines:
Thread.new {
#page_graph.put_connections('mypage-id', "MyApp:MyAction", :MyObject=> url_for(#myobject), :image=> image_location)
}
any idea what might be the cause of this issue, or how can I debug this?
BTW, the app is hosted on Heroku and Heroku logs doesn't show any errors
Update:
I can successfully post the simple message with these lines as well:
#page_graph.put_connections('mypage-id', 'feed', :message => 'This is posted as the page 2')

Rails EOF Error when using HTTP.get_response to retrieve Facebook access token

I trying to implement a Login with Facebook feature on my site, and hitting a roadblock trying to get the access token back from Facebook. Here is my code:
if params[:error_reason] == "user_denied" then
flash[:error] = "To login with Facebook, you must click 'Allow' to let the site access your information"
redirect_to :login
elsif params[:code] then
token_uri = URI.parse("https://graph.facebook.com/oauth/access_token?client_id=****************&redirect_uri=http://localhost:3000/auth/fblogin&client_secret=***************&code="+URI.escape(params[:code]))
response = Net::HTTP.get_response(token_uri)
session[:response] = response
data = ActiveSupport::JSON.decode(response)
access_token = data[:access_token]
flash[:error] = access_token
redirect_to :register
end
This is inside a fblogin controller function that is the target of the initial redirect to get an authorization code (the params[:code]).
But when I run through this, I get the following error:
EOFError in AuthController#fblogin
on the Net::HTTP.get_response(token_uri) line. I've searched all over, and can't find anything to indicate what this means. Could it be the obscure characters Facebook uses in their access tokens? I'm totally lost!
You are receiving an EOFError because you are trying to connect to an https URL using code that only works with http. See the section entitled "SSL/HTTPS request" at this Net::HTTP Cheat Sheet for the basics.
However, I would recommend using a third-party library to manage this for you, such as OAuth2 for utilizing Facebook's OAuth2 API, where you'd write code like this:
def client
OAuth2::Client.new('app_id', 'app_secret', :site => 'https://graph.facebook.com')
end
# in your callback code:
access_token = client.web_server.get_access_token(params[:code], :redirect_uri => 'http://localhost:3000/auth/fblogin')
user = JSON.parse(access_token.get('/me'))
If you really want to make the requests yourself, you can look at libraries like Faraday to execute the HTTPS requests for you.

Resources