mini fb posting to friend's wall using graph api - ruby-on-rails

Hi I have read all the other post relating to this but I think I am missing something fundamental. I am using mini_fb in my ruby on rails application for handling the facebook api. I have the following code:
current_user.session.post('me', :type => :feed, :params => {:name => "name",
:to => "{\"data\":[{\"name\":\"#{friend.facebook_name}\",\"id\":\"#{friend.facebook_id}\"}]}",
:link => url_of_app,
:description => "desc",
:actions => "{\"name\": \"action name\", \"link\": \"url\"}"})
The above posts to the current user's wall with or without the "to" parameter set. Everything works, except for the "to" parameter. I have read the graph post to wall over and over again and I can't figure out what is wrong with this code of mine. I would really appreciate it if someone could point out my mistake.

I've never used ruby's version, but probably the problem is in the first parameter. You are targeting 'me' feed, while should be targeting your friends feed. Try fetching your friend id and doing something like
current_user.session.post(friend.facebook_id, :type => :feed, :params => ...)

Wow, mini_fb looks so verbose :)
Telémako is right, you need to use your friends id. I give you another alternative for more nice code. Use Koala.
https://github.com/arsduo/koala/wiki/Graph-API
#graph.put_wall_post("explodingdog!", {:name => "i love loving you", :link => "http://www.explodingdog.com/title/ilovelovingyou.html"}, "tmiley")
=> {"id"=>"83901496_520908898070"}
I use it in my projects and works very well.

Related

How to use Rails detect in Rails on incoming Params

So recently I was helped out finding a way of using detect in rails to grab a url from text... however that would come very useful for me also in a controller if its possible.
My controller grabs some info and created a new entry into the DB based on incoming params, looks something like this;
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new')
Now, I was hoping that using detect in my controller on the create action, I could search the :content for specific text or symbol and allow my users to define few things in content but I would assign that to a different column. I'm sure this isn't clear so let me show by example.
EXAMPLE:
Let's say my user send a message with content like so;
"Hey there, you should check this type of website out and make sure that its good to go"
Now, I'm assigning a USER_ID for the user that submitted this message, but the original owner could be someone else before the user submitted it. So I thought I would allow my user_id to enter #John into their message, meaning the original owner of the message was JOHN.. the new message would look something like this;
"Hey there, you should check this type of website out and make sure that its good to go #John"
Now in my controller when that message is created as a record, I'd like to take JOHN and assign it to the column username for example; I thought something like this would work but its giving me error .detect undefined..
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => (params[:Text].detect {|original_sender| original_sender.start_with? "#"))
Maybe too many brackets?
you are missing } at the end
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => (params[:Text].detect {|original_sender| original_sender.start_with? "#"}))
you can also use the below for what you want
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => params[:Text].split.find{|w| w.start_with?("#")})

How to post user generated photos to Facebook using Koala?

I'm using the Koala gem in a Rails 3.2 app.
I'm trying to post an action that includes a user generated photo to a Facebook application. According to FB's docs, the url I need to post to is:
https://graph.facebook.com/uid/namespace:action?object=http://path/to/page&image[0][url]=http://path/to/image.jpg&image[0][user_generated]=true
If I test this manually using Facebook's debugger, it works perfectly. But I'm having trouble achieving this with Koala.
I'm using the following method:
Koala::Facebook::API.new(app_token).put_connections( uid, namepsace:action, url )
If I use:
url = "http://path/to/page"
then the action is posted to Facebook correctly, but without the user generated photo.
If I use:
url = "http://path/to/page&image[0][url]=http://path/to/image.jpgimage[0][user_generated]=true"
I receive an error in the logs
#<Koala::Facebook::APIError: OAuthException: (#3502) Object at URL http://path/to/page&image[0][url]=http://path/to/image.jpg&image[0][user_generated]=true has og:type of 'website'. The property 'object' requires an object of og:type 'namespace:object'. (http response code: 404)>
What is the correct way to construct the required post url using Koala? Or what is a good approach to begin debugging my current code? Or am I totally on the wrong track with this?
I struggled a ton with this too, both because of Facebook's documentation and Koala's which are not super clear in my opinion:
Koala::Facebook::API.new(access_token).put_connections(
uid,
"namespace:action",
"product" => "[URL_TO_PRODUCT]",
"image[0][user_generated]" => true,
"image[0][url]" => "[URL_TO_USER_GENERATED_IMAGE]",
"fb:explicitly_shared" => true,
"message" => "[DESCRIPTION]"
)
The other thing was that the target URL had to have og:type="namespace:product"
Hope this helps
Have you checked your url in Facebook Debugger?
http://developers.facebook.com/tools/debug
From error message you got it looks like you should set og:type to namespace:object and to get custom image you should set og:image to http://your.domain.com/path/to/user/generated/image
I was using put_connections, like you, but it's not necessary, you can use the method put_wall_post.
I asked for the permission: publish_actions.
And in my Controller's method I have:
api = Koala::Facebook::API.new(#oauth_token)
api.put_wall_post("Testing post on Timeline", {
:name => "Im a wall post",
:link => "http://www.example.com",
:caption => "Im a caption",
:description => "Im a long description of an attachment",
:picture => "http://www.example.com/picture.jpg"
}, #users_facebook_id)
With this, you can post to the user's Timeline, having an image, a description, etc.

Am I posting to Facebook correctly?

Anyone use the Koala gem to post on a Facebook wall before? I am able to post fine (with the picture displayed), but can't seem to have the "share" link on the actual wall post. "Like" and "Comment" appear though.
I have the following:
client = Koala::Facebook::API.new(user.token)
options = {
:message => "Message here",
:description => "Description here",
:link => "http://#{APP_CONFIG['host']}/foobars/1",
:picture => "#{photo.url}"
}
client.put_object(user.facebook_uid, 'feed', options)
Am I missing something in options? Would anyone like to share their experience?
Seems to work by changing feed to links:
client.put_object(user.facebook_uid, 'links', options)

Docmail API for ROR application for postcard

I am using docmail's Simple API for sending Postcard.They have implemented this functionality recently, but I didn't get any sample code or instruction for implementation.
Thanks in advance,
Gaurav Soni
I got my answer.Here is a sample code that can interact with Docmail Simple API methods.
require "base64"
require "soap/wsdlDriver"
class TestDocmailLetterSending
def initialize(account)
api="https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?wsdl"
#test = SOAP::WSDLDriverFactory.new(api).create_rpc_driver
contents = open(file, "rb") do |f|
f.read
end
result = #test.sendLetterToSingleAddress(
'sUsr' => "username",
'sPwd' => "password",
'sMailingName' => "string",
'sCallingApplicationID' => "string",
'bColour' => true,
'bDuplex' => true or false,
'eDeliveryType' => "StandardClass",
'sTemplateFileName' => File.basename(file),
'eAddressNameFormat' => "FullName",
'bTemplateData' => contents,
'sFirstName' => first_name,
'sLastName' => last_name,
'sAddress1' => "",
'sAddress2' => ,
'sAddress3' => ,
'sAddress4' => ,
'sPostCode' => ,
'bProofApprovalRequired' => 'false'
)
end
end
We don't have any RoR examples at this time - others here may be able to help, but it's essentially a SOAP webservice, with the SimpleAPI using less complex data types than the standard version. The standard API already lets you send postcards and letters, but is more complex to use from some environments due to it's complex data types.
The test version of Docmail's SimpleAPI has now been updated to expose postcard calls to allow physical postcards to be send via the Simple version of the API. Once we're happy with the updates, we'll make them available in the live version too.
Although you've probably already been through the other info on the API, here are some links/addresses in case anyone else needs them:
Docmail API Info Page
Simple API Test Webservice & Website (for the Simple API Live versions, replace "Test" with "Live"):
https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?WSDL
https://www.cfhdocmail.com/Test
Hope that helps.
Will
(from Docmail)

403 Error when Authenticating using tumblr gem for rails application

I have a ruby-on-rails application that wishes to utilise the tumblr gem for adding posts when an action is taken (eg: creating a blog post)
I currently have the tumblr gem installed and can manage to fetch my posts using
#tumblruser = Tumblr::User.new('myemail','mypassword')
However when i go to add a post where it asks me to pass the user information like so (according to the API for the gem)
post = Tumblr::Post.create(#tumblruser, :type => 'video', :embed => #post.video_html, :title => #post.title, :caption => #post.content)
it just does not want to authenticate and returns a 403 error
anyone had any experience with this?
NEW SOLUTION:
I have found recently that there has been a problem with the gem. So I have made a copy of it, changed a few things in the docs and code and put it at http://rubygems.org/gems/matenia-tumblr-api
Hope the changes and docs help someone else out there.
As always I welcome any improvements, or refactoring on any of my projects.
Kind Regards,
Matenia
OLD ANSWER BELOW
I managed to get around this by the way ... all i did was declare the username and password in place of #tumblruser like so:
post = Tumblr::Post.create(:email => 'user name email here',
:password => 'my password',
:type => 'video',
:embed => #post.video_html,
:caption => #postcontent)
where #postcontent is the html text of post.content and gsubbed to escape most of the html.
hope this saves someone else some time.
If you are only going to check authentication with any media like Facebook , Twitter ,LinkedIn ,Tumblr , Github and almost 20 others (you can check Here ) .Then omniauth gem is the first thing that comes to mind . Means It's clearly simplest solution for authentication and I love it

Resources