Koala fails to perform put_connections as a page - ruby-on-rails

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')

Related

Gibbon API does not error, but does not subscribe

This is a strange one. I've had a working MailChimp, Gibbon, RoR app going for a couple of years now, and I went to go use part of my app this week and realized that the integration was no longer working. I am not receiving any errors, and some basic testing shows that the exception section of the code is never called.
Here is the code I am using:
begin
gb = Gibbon::API.new(mailchimp_api_key)
gb.lists.subscribe( id: mailchimp_list_id, email: {email: email} )
rescue Gibbon::MailChimpError => e
logger.error "Mailchimp threw an error. The code is: #{e.code}, with message: #{e.message}"
end
Some code edited for readability, but assume that the variables are defined and no errors are thrown.
What I'm looking for is some debugging help. I can't seem to find a way to debug the integration to know if there is something silently failing or not. Does anyone have any tips for debugging this outside of trying to catch a raised exception?
I use the same code and when something wrong an exception is thrown.
You should check and print what subscribeis returning.
response = gb.lists.subscribe( id: mailchimp_list_id, email: {email: email} )
puts response
According to the mailchimp documentation it should return a JSON like this one :
{
"email": "example email",
"euid": "example euid",
"leid": "example leid"
}
https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
Thanks!
And yep, I do get a response back that matches what you suggested (note, I used a real email address):
{
"email"=>"my#email.com",
"euid"=>"3cb513752a",
"leid"=>"89681797"
}
Strangely enough, it does show up on the mailchimp side as pending subscription, but the subscription confirmation is not sending. That sounds like I have a MailChimp problem, not a gibbon problem. Does anyone know of a setting on the MailChimp side I am missing?
Will keep digging...

Get code for your action and see in my timeline

I'm building an Open Graph action.
Before I was using curl in command line in order to post in my timeline, now when I'm using this command, nothing appears in my timeline.
The response is correct in the graph. And I can see my all those actions on my graph but still nothing on my timeline https://graph.facebook.com/me/[namespace]:[action]?access_token=[...]
I don't understand what is happening
I'm using fb_graph gem in the back-end
def self.action(objet, user, url)
me = current_user.facebook
Thread.new do
sleep(4)
action = me.og_action!(
FACEBOOK_NAMESPACE+":action",
:objet => url
)
end
end
This has always worked
Any idea ?
Thanks
Maxime

How to add comment in website page by API? [duplicate]

I have facebook social comments box. How can I post comment through graph API to it?
I can give you half the answer to this question, but still need the other half very much myself. You can post a reply to an existing comment within Social Comments box by finding its post_fbid. To get this you can use FQL such as:
https://api.facebook.com/method/fql.query?query=SELECT post_fbid, id FROM comment WHERE object_id IN (SELECT comments_fbid FROM link_stat WHERE url ='[ PAGE_URL ]')&access_token=[ ACCESS_TOKEN ]
This query will need to be run through an escape() with the PAGE_URL and then used for an HTTP GET request:
https://api.facebook.com/method/fql.query?query=SELECT%20post_fbid%2C%20id%20%0A%20%20%20%20%20%20%20%20FROM%20comment%20%0A%20%20%20%20%20%20%20%20WHERE%20object_id%20IN%20%0A%20%20%20%20%20%20%20%20%20%20(SELECT%20comments_fbid%20%0A%20%20%20%20%20%20%20%20%20%20%20FROM%20link_stat%20%0A%20%20%20%20%20%20%20%20%20%20%20WHERE%20url%20%3D'http%3A%2F%2Fexample.com')&access_token=[ ACCESS_TOKEN ]
With the post_fbid you can make a reply by doing an HTTP POST to:
https://graph.facebook.com/[ POST_FBID ]/comments/?access_token=[ ACCESS_TOKEN ]&message=[ MESSAGE]
Now for posting a new comment to the page this used to work until recently with an HTTP POST:
http://graph.facebook.com/comments/?ids=[ PAGE_URL ]&access_token=[ ACCESS_TOKEN ]&message=[ MESSAGE]
But currently this is consistently returning:
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException"
}
}
I hope this helps a bit and if anyone can shed some light if posting a new comment like this is even possible anymore it would be greatly appreciated.
Seems that it is not possible, and will never be:
This functionality was never and is not intended to be available.
An error message has been added for this case: "Comments may not be
added to a comment plugin"
https://developers.facebook.com/bugs/164794086987157
Its very easy as you post on user feed after getting access_token with publish stream token
I assume you use PHP SDK if you need in other let me known
You just need Step 4 but i give you more details in Step 1 to 3 so you can understand and do clearly
Step 1
get the user access token
$token = $facebook->getAccessToken();
echo "</br>" . 'Access_Token:' . $token;
Step 2
set default access token and profile
$facebook->setAccessToken($token);
Step 3
compile the post
$WallPost = array(
'message' => 'hey this app is cool!!',
'link' => $canvas_page,
'caption' => 'caption',
'description' => 'Test Description',
); // you can also use 'picture', 'description', 'source'....
Step 4
post to wall or your Social Comment Plugin
$response = $facebook->api('/me' . '/feed','POST',$WallPost);
Thanks

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

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.

Using Koala, how can I attach an image when I publish to a user's stream?

I've started to play with the Koala gem for a RoR app. I've already got permission from the user to publish to their stream
After this line
graph = Koala::Facebook::GraphAPI.new(#facebook_cookies["access_token"])
to post to the stream, I can do a
graph.put_object("me", "feed", "I am writing to my wall")
The above works, but how do I include an image like http://example.com/foo.jpg as part of the update? I tried reading up the Stream Attachments but without a lot of luck. Does anyone have some sample code?
You can use something like:
options = {
:message => "I am writing to my wall",
:picture => "http://example.com/foo.jpg"
}
graph.put_object(facebook_uid, "feed", options)

Resources