403 Error when Authenticating using tumblr gem for rails application - ruby-on-rails

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

Related

"Postmark::InvalidMessageError: Provide either email TextBody or HtmlBody or both." for a rails 3.2 app

I was reading through the Postmark documentation, saw the rails gem there (github link).
I set it up according to the instructions and I ran into this message when I tried sending an email:
Provide either email TextBody or HtmlBody or both.
I have my email settings in my mailer as such:
mail(
:to => user.email,
:subject => "Thanks for signing up",
:from => "me#domain.com",
"HtmlBody" => "<b>Hello</b>",
"TextBody" => "Hello"
)
Please let me know if you need more information. I'm not sure if this is detailed enough for someone who has seen this error before.
Misnaming Email Views
I ran into this same thing and it was due to a misnaming on my part of the views associated with the email.
Example
_user_first_logs_in.html.erb # Was incorrectly using this.
user_first_logs_in.html.erb # Should be using this.
A good way to test for this locally is by using the mail_view gem by our trusted 37signals boys that allows you to preview email in development. Check it out.
That should expose a lot of basic issues.
JP

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.

Using templates for Pony gem

I recently came across sending emails via Rails. After watching railcast, it seems that you can write up a template when using Action Mailer. I really liked this feature for my purpose. I also came across Pony, which seems really easy to use.
I was wondering if I can use templates for sending emails via Pony, unless Pony is meant for express non-templated emails.
You can easily access the view framework by explicitly rendering a template:
Pony.mail(
:to => 'somewhere#example.com',
:from => 'sender#other.example.com',
:subject => 'an example',
:body => render_to_string("path/to/_partial", :locals => {foo: #foo}, :layout => false)
)
In my research, Pony seems to be promoted as a non-template based tool, making it "simpler" to use. The home page for the utility does not mention templates at all:
https://github.com/benprew/pony

Create record example for Quickbooks Online and Intuit Anywhere using Ruby and httparty?

Can someone post an example of creating a record in quickbooks online / intuit anywhere, using ruby and httparty?
I am working on an integration to a ruby on rails app using intuit anywhere, and am running into an issue with my POST request when attempting to create a new record. I have been able to successfully retrieve data (customers) using a POST command that doesn't require XML data in the body of the request, but am running into trouble when trying to create new records that have required fields that need to be passed in XML in the body of the request.
I get the same flavor of error in any entity for which I try to create a record for: an invalid or missing required field. It seems to me that the XML in the body (where the data for the required fields is added) is either being ignored (incorrect formatting?) or is not being attached.
I was hoping the someone else familiar with ruby could post an example of a record creation using httparty. If I could see how to correctly pass the XML using httparty, I can fix my problem myself.
I have been using the customer.com example (https://code.intuit.com/integration/viewvc/viewvc.cgi/IntuitAnywhere-Ruby/customer.com/?root=intuitanywhere&system=exsy1003) mostly as posted, with a few irrelevant modifications needed to get it to work in Rails 3.1. I am using the data pull and handling provided in the example, which looks like a pretty standard API wrapper built using httparty.
I am using a pull similar to the one found in the company_controller customers method. Here are two different ways I have tried submitting the XML:
#########################################
#Example 1 - XML
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body =>
"<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\">
<Name>Test Account 2</Name>
<Desc>Test Account</Desc>
<Subtype>Savings</Subtype>
<AcctNum>5001</AcctNum>
<OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
</Account>",
:headers => {
"Content-Type" => "application/xml"
}}
)
#########################################
#Example 2 - hash
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body => {
:Account => {
:Name => "Loan Account 2",
:Desc => "Loac Account 2",
:Subtype => "Savings",
:AcctNum => "5001",
:OpeningBalanceDate => "2011-04-22"
}
},
:headers => {
"Content-Type" => "application/xml"
}}
)
I incorrectly assumed the customer.com example provided by intuit was using the httparty gem to make the POST call, so I was using the wrong syntax. They are actually using the OAuth gem's POST call, who's syntax can be found here: http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
I also had to modify the headers to get the Intuit Anywhere service to accept the XML body. Here is the code that finally worked for me to create a record in quickbooks online using intuit anywhere:
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}", "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\"><Name>Test Account </Name><Desc>Test Account</Desc><Subtype>Savings</Subtype><AcctNum>5002</AcctNum><OpeningBalanceDate>2010-05-14</OpeningBalanceDate></Account>", {"Content-Type" => "application/xml", "standalone" => "yes", "encoding" => "UTF-8"})

mini fb posting to friend's wall using graph api

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.

Resources