salesforce sandbox integration in rails, error expired access - ruby-on-rails

I am using the Ruby Gem "databascdotcom" to integrate Salesforce in a Rails app and all works fine until i try it with sandbox account type "Configuration Only".
The following code work fine when i used with salesforce product account.
Here is my code
def SalesForceFeed
#oppID = params[:oppid]
client = Databasedotcom::Client.new client.client_id #=> foo client.client_secret #=> bar
client.authenticate :username => "foo#bar.com", :password => "ThePasswordTheSecurityToken" #=> "the-oauth-token"
client.materialize("Opportunity")
begin
#client=SalesForce::Connection.new.client
#opp = Opportunity.find_by_Id(#oppID)
rescue Exception=>e
end
But when i try to use it with salesforce sandbox account with username like "foo#bar.com.sandbox"
I m getting following error "expired access/refresh token"
Any ideas?

Got the issue.
Just need to add
host= "test.salesforce.com"
Thanks All

Related

Unsupported get request - Facebook Marketing API won't authenticate for me

I'm setting up an API integration in my rails application with the Facebook Ads/Marketing API. I'm attempting to test very basic options with my Sandbox Ad Account and cannot seem to get them to work. This is error I keep getting:
FacebookAds::ClientError: Unsupported post request.
Object with ID '119033245616727' does not exist, cannot be loaded due
to missing permissions, or does not support this operation.
Please read the Graph API documentation at
https://developers.facebook.com/docs/graph-api: (fbtrace_id: GyiFjx24NY/)
from /Users/kelly/.rvm/gems/ruby-2.3.0/gems/facebookads-0.2.11.0/lib/facebook_ads/api_request.rb:67:in `create_response'
To run the test, I used their Marketing API quickstart to get my access token, app secret and ad account id.
This is my rails config:
Gemfile:
gem 'facebookads' #https://github.com/facebook/facebook-ruby-ads-sdk
My Test Module:
module Advertising
module Facebook
class API
attr_accessor :access_token
attr_accessor :app_secret
attr_accessor :ad_account_id
def initialize
#access_token = 'EAAYVZBezhACwBAKwMk7fhAJO2WFlUeUaCcASveD9gb6ZCKBzEAJIzDToagt4Vy5n6Ue9QpOwyb0SWYCSHHf4A2jbdTOb99GTBjhSOu5WnU03mnKymd2YgmquOJHg4lPx3iZBonYTzriU27OnlBXDMXdIZApwt45SSqQ8SLs5xaMM3lVEsm0r6WXSoos5yiOiqfMB83SfnntzUzqkEywQ'
#app_secret = '15326d2073b04504ef72267bf36a8bd4'
#ad_account_id = '119033245616727'
end
def test1
FacebookAds.configure do |config|
config.access_token = #access_token
config.app_secret = #app_secret
end
ad_account = FacebookAds::AdAccount.get(ad_account_id)
ad_account.campaigns.create(
objective: 'LINK_CLICKS',
status: 'PAUSED',
buying_type: 'AUCTION',
name: 'My Campaign'
)
end
def test2
# With session
session = FacebookAds::Session.new(access_token: #access_token, app_secret: #app_secret)
ad_account = FacebookAds::AdAccount.get(ad_account_id, session)
puts "This is my account name: #{ad_account.name}"
end
end
end
end
Then I'm running this in the rails console:
ad = Advertising::Facebook::API.new()
ad.test1
# OR
ad.test2
This is a newly created facebook app. These are the settings:
Status: In Development
App ID: 1713013025472556
App Secret: 15326d2073b04504ef72267bf36a8bd4
I added the Marketing API to the products section and created a Sandbox Ad Account called T2 Sandbox (119033245616727).
When setting your ad_account_id, add 'act_' in front of the ID. As the SDK will not do this for you.

rails activemerchant authorize.net problems

I have an Authorize.net account for CC processing on my ecommerce site, and I use ActiveMerchant to authoenticate transactions. It worked just fine until a while ago, and then it stopped. I cannot figure out why. When I run it in test mode, it works fine, creates the transactions and successfully authorizes the funds. But when I try with real account, it fails. When I run it from the console, here is the code:
cc_hash =
:first_name => 'Donald',
:last_name => 'Duck',
:number => '4007000000027',
:month => '8',
:year => Time.now.year+1,
:verification_value => '000'
}
card = ActiveMerchant::Billing::CreditCard.new(cc_hash)
#--- valid?
RYeller.bar
if card.valid?
puts "card valid"
else
puts "card not valid"
end
#ActiveMerchant::Billing::Base.mode = :test
#gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(:login=>'scrubbed',:password=>'scrubbed')
ActiveMerchant::Billing::Base.mode = :production
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(:login=>'scrubbed',:password=>'scrubbed')
amount = rand(1000)+2500
options = {}
options[:order_id] = "WEBSITE 26"
options[:description] = 'WEBSITE TEST'
#--- authorize transaction
response = gateway.authorize(amount, card, options)
puts response.inspect
When I run this in test mode, in my sandbox account (the two lines commented out in the code above) - it works fine. When I run it on my real account (the code as is above) - I get an error: "An error occurred during processing. Call Merchant Service Provider." The full response hash is:
#<ActiveMerchant::Billing::Response:0x1078607d8 #fraud_review=false, #params={"response_reason_code"=>"35", "avs_result_code"=>"P", "transaction_id"=>"scrubbed", "response_code"=>2, "response_reason_text"=>"An error occurred during processing. Call Merchant Service Provider.", "card_code"=>"P"}, #message="An error occurred during processing. Call Merchant Service Provider", #authorization="scrubbed", #test=false, #cvv_result={"message"=>"Not Processed", "code"=>"P"}, #success=false, #avs_result={"message"=>"Postal code matches, but street address not verified.", "street_match"=>nil, "postal_match"=>"Y", "code"=>"P"}>
I am using a test CC number and the card.valid? test returns true.
When I look at the transaction in Authorize.net, I see all the transaction created and all the info properly there, but the Transaction Code is General Error.
Any ideas? Help greatly appreciated, I am at the end of my rope here and sinking fast.
Is your production Authorize.net in test mode? If not, Donanld Duck isn't going to be able to check out with a fake credit card.
You should be able to login to your production Authorize.net account and see the test order as a decline. If you do then everything is working and you will need to test with a real card to get a successful transaction. If you want to test with a fake card you will need to set you production account back to testing.

Analytics API integration rails failing on heroku production

I am currently developing a ruby on rails application which includes the gattica gem to fetch Google Analytics data. When I fetch my data:
https://github.com/activenetwork/gattica
gs = Gattica.new({:email => 'johndoe#google.com', :password => 'password', :profile_id => 123456})
results = gs.get({ :start_date => '2008-01-01',
:end_date => '2008-02-01',
:dimensions => 'browser',
:metrics => 'pageviews',
:sort => '-pageviews'})
on development I will simply receive a response which I can parse to my application.
However on production the page returns a 500 error and in my Gmail inbox I receive a message about a suspicious login being caught.
Is there any way I can fix this issue?
PS: my application is hosted on Heroku.
With kind regards,
Dennis
You're getting the 500 error because Google is blocking your heroku ip from accessing your account. They aren't sure it's you.
You need to change your activity settings to authorize that ip/domain.
Read this: https://support.google.com/accounts/answer/1144110?hl=en&ref_topic=2401957
Also, its a good idea to read your logs when debugging these kinds of errors. Rails.logger.debug results could shed some light.

How to handle user revoking LinkedIn access in rails

How should I handle a user revoking my access to their LinkedIn account? I am using Ruby on Rails with Omniauth, Omniauth-LinkedIn and linkedin gem (latter incorporates oauth gem).
My controller code
if !#user[:lnk_token].nil?
client = LinkedIn::Client.new("xxxx","xxxx")
client.authorize_from_access(#user[:lnk_token].strip,#user[:lnk_access_token_secret].strip)
#lnk = client.profile(:fields => ["picture-url", "positions", "educations"])
end
Use a simple error handler:
if !#user[:lnk_token].nil?
client = LinkedIn::Client.new("xxxx","xxxx")
client.authorize_from_access(#user[:lnk_token].strip,#user[:lnk_access_token_secret].strip)
begin
#lnk = client.profile(:fields => ["picture-url", "positions", "educations"])
rescue
#lnk = nil
end
end
Further reading: http://rubylearning.com/satishtalim/ruby_exceptions.html

"Missing authorization code" error when trying to use Google Calendar API

The following is the code I am using to allow users to allow users to authorise my app to access their Google Calendar via OAuth. I based it off this sample code.
It works most of the time, but sometimes, there is an ArgumentError: Missing authorization code error on the client.authorization.fetch_access_token! line in the create_google_calendar action in the services controller. If I comment out that line, all of the client.authorization attributes are null.
I am using Rails 3.2.0 and Ruby 1.9.2.
What is causing this?
Gemfile
gem 'google-api-client', :require => 'google/api_client'
service.rb
def self.google_calendar_client google_calendar_service=nil
client = Google::APIClient.new
client.authorization.client_id = xxx
client.authorization.client_secret = xxx
client.authorization.scope = 'https://www.googleapis.com/auth/calendar'
url_prefix = Rails.env.production? ? xxx : 'http://localhost:3000'
client.authorization.redirect_uri = "#{url_prefix}/create_google_calendar"
if google_calendar_service.present?
client.authorization.update_token! :access_token => google_calendar_service.token, :refresh_token => google_calendar_service.google_calendar_refresh_token, :expires_in => google_calendar_service.google_calendar_expires_in, :issued_at => Time.at(google_calendar_service.google_calendar_issued_at)
client.authorization.fetch_access_token! if client.authorization.expired?
end
client
end
services_controller.rb
def connect_google_calendar
#google_calendar_url = Service.google_calendar_client.authorization.authorization_uri.to_s
end
def create_google_calendar
client = Service.google_calendar_client
client.authorization.code = params[:code]
client.authorization.fetch_access_token!
current_user.services.create :provider => 'google_calendar', :token => client.authorization.access_token, :google_calendar_refresh_token => client.authorization.refresh_token, :google_calendar_expires_in => client.authorization.expires_in, :google_calendar_issued_at => client.authorization.issued_at
end
The truth is, I don't know. Your code looks right to me. But I can at least tell you what the error means. Missing authorization code means that it thinks you're trying to do an "authorization code" grant type when you fetch the access token. If you're actually trying to obtain an access token off a refresh token as opposed to doing it on the first pass after obtaining authorization from the user, then you may not have correctly set up the authorization object.
You can check this by inspecting the client.authorization.grant_type value. In very recent versions of the client you can manually set the grant_type value to force a particular mode, which may give you more informative error messages, depending on what the actual issue is.

Resources