google-api-client suddenly comes back with "invalid request" - google-api-client

I've been running Ruby scripts for weeks now using a Service Account, but today I'm getting an "Invalid Request" when I try to build the client using the following function:
def build_client(user_email)
client = Google::APIClient.new
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/calendar',
:issuer => SERVICE_ACCOUNT_EMAIL,
:signing_key => Google::APIClient::KeyUtils.load_from_pkcs12(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret"),
:person => user_email
)
client.authorization.fetch_access_token!
return client
end
Is there a lifespan on Service Accounts? I tried creating another Service Account and using that but I get the same result:
Authorization failed. Server message: (Signet::AuthorizationError)
{
"error" : "invalid_request"
}
Stumped!

OK. I figured it out. It was all to do with the user_email. I was reading it from a file and forgot to chomp the linefeed off, so it was objecting to a mal-formed email address.

Related

Ruby date format for PayPal Button Manager API

I can't get a date format that PayPal will accept via its PayPal Button manager API. "The start date specified is invalid." is the error.
Attempt 1: copy the string directly from the documentation:
"start_date": "2017-12-22T09:13:49Z"
I saw this https://github.com/paypal/PayPal-Ruby-SDK/issues/107 so tried
strftime('%Y-%m-%dT%H:%M:%SZ') and utc.iso8601
start_date = "1980-02-19T00:37:04Z"
start_date = (DateTime.now - 10.years).utc.iso8601
start_date = (DateTime.now - 10.years).utc
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
# Make API call & get response
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
#Errors=[#<PayPal::SDK::ButtonManager::DataTypes::ErrorType:0x007fa58b12e110 #ShortMessage="Invalid Argument", #LongMessage="The start date specified is invalid.", #ErrorCode="11998
(byebug) #bm_build_button_search.start_date.class
PayPal::SDK::Core::API::DataTypes::SimpleTypes::DateTime
So it looks like PayPal is fine with this DateTime format but when I call
#api.BMButtonSearch(#bm_build_button_search)
I get the error #LongMessage="The start date specified is invalid."
I just verified following script using Ruby version 2.3.3 and its working fine. Following is the script i used in ruby console.
Step1: install Paypal SDK
$ gem install paypal-sdk-buttonmanager
Step2:
require 'paypal-sdk-buttonmanager'
#api = PayPal::SDK::ButtonManager::API.new(
:mode => "sandbox", # Set "live" for production
:app_id => "APP-80W284485P519543T",
:username => "jb-us-seller_api1.paypal.com",
:password => "WX4WTU3S8MY44S7F",
:signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-
RWy" )
Step3:
start_date = "1980-02-19T00:37:04Z"
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
Response: I, [2017-05-06T05:43:14.803444 #6541] INFO -- : Action: BMButtonSearch
I, [2017-05-06T05:43:14.803551 #6541] INFO -- : Request[post]: https://api-3t.sandbox.paypal.com/2.0/
I, [2017-05-06T05:43:27.057413 #6541] INFO -- : Response[200]: OK, Duration: 12.254s
**Please verify using Ruby 2.3.3. Screenshot has been attached. thanks!**
reference: https://github.com/paypal/buttonmanager-sdk-ruby

Laravel Mail::Send works on local apache but complains about mime on nginx

I have installed a laravel package for user verification
https://github.com/jrean/laravel-user-verification
Register Controller needs to be changed to work like below.
public function register(Request $request)
{
$this->validator($request->all())->validate();
$user = $this->create($request->all());
$this->guard()->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'Verification Mail from example.com');
return redirect()->intended('/home');
}
Used mailgun to send mails.It worked fine on local apache. sent mails successfully to gmail and others.
Installed on nginx production(ubuntu 16.04 VPS ). It throws following error.
FatalThrowableError in SimpleMessage.php line 33:
Type error: Argument 1 passed to Swift_Mime_SimpleMessage::__construct() must
be an instance of Swift_Mime_HeaderSet, none given, called in /var/www/example.com/
html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php on line 48
To check if it is a package problem I have also done the following which works on local apache but throws the same error on nginx.
Route::get('/mailsend', function() {
$data = [
'title' => 'hello user',
'content' => 'Thanks for joining us'
];
Mail::send('mails.test', $data , function($message) {
$message->to('example#gmail.com','example')->subject('Testing from example');
});
});
The code as shown in error /Swift/Message.php in line 48 as follows
call_user_func_array(
array($this, 'Swift_Mime_SimpleMessage::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.message')
);
Could not figure out the problem with nginx. Any help would be greatly appreciated.
Try uncomment line: extension=php_openssl.dll on php.ini
and check this https://laravel.io/forum/05-13-2014-smtp-mail-not-working-in-live-server

Resque Workers on Heroku locked out of Postgres DB SSL- no fix yet

I'm using resque/redis on heroku to send emails as a background job. It works fine for the first email I send, but after that I get the error: (ActiveRecord::StatementInvalid: PG::Error: SSL error: decryption failed or bad record mac :) ...
I've seen the other questions/answers that say to add to an initializer:
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
OR
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
However, I have done this (and tried any other thing I can think of) and I'm still getting the same error. I have run the code with only before_fork and only after_fork to no avail.
I am also using APN_sender to send apple push notifications. The workers for these have had no problems (but I'm calling default Heroku workers to do these rather than Resque workers).
Here are my relevant files, please help! This is my first SO question as well.. apologies if it's not done perfectly.
#config/resque.rb
after_fork do |server, worker, resque|
logger.info("Got to after_fork in resque.rb config file")
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
--------------------
#config/initializers/resque.rb
require 'resque'
require 'resque/server'
heroku_environments = ["staging", "production"]
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
#confusing wording.. determines whether or not we are in Production, tested and working
unless heroku_environments.include?(rails_env)
resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
else
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end
----------------------
#resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
task "apn:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
desc "Alias for apn:work (To run workers on Heroku)"
task "jobs:work" => "apn:work"
-----------------------
#Sending the email
#event.guests.each do |g|
Resque.enqueue(MailerCallback, "Notifier", :time_change, #event.id, g.id)
end
I am running one Heroku worker and one Resque worker from the Heroku ps:scale command. As I said, the first email sends error-free, and then any emails after get the above error.
Thanks in advance!
Mike
OK, so couldn't figure this out...
Switched over to delayed job and it's working much better. A little frustrating that I can't send push notifications with apn_sender anymore, but apn_on_rails is working fine.
Weird problem, still curious...

Magento SOAP 2 API Fatal error: Procedure 'login' not present

I am getting: Fatal error: Procedure 'login' not present in /chroot/home/mystore/mystore.com/html/lib/Zend/Soap/Server.php on line 832
This is where the error is coming from
$soap = $this->_getSoap();
ob_start();
if($setRequestException instanceof Exception) {
// Send SOAP fault message if we've catched exception
$soap->fault("Sender", $setRequestException->getMessage());
} else {
try {
$soap->handle($request);
} catch (Exception $e) {
$fault = $this->fault($e);
$soap->fault($fault->faultcode, $fault->faultstring);
Any Ideas on how to fix the error?
I had the same issue, and which I did to fix it was to go to System/Configuration/Magento Core API and set the value WS-I Compliance as 'No'.
I'm working with a WebService which consumes the Magento V2 API, I don't recall if I generate the web reference using this value as 'Yes'; I'm working with a WS C# using VS 2010.
I had similar problem and I did not want to change the API version. Deleting the WSDL cache helped me.
Run this to get the WSDL cache folder:
php -i | grep soap
From the result you can see that the WDSL cache is enabled and stored in /tmp:
soap
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400
Remove the cache and run it again:
sudo rm -rf /tmp/*
I found the clue in this article - http://artur.ejsmont.org/blog/content/php-soap-error-procedure-xxx-not-present

500 error when calling webservice through rhosync/rhodes

I am trying to call a web service in rhosync application.rb, I see a 500 error response in rhosync console .. and 'server returned an error' in BB simulator .. :(
Some info about my setup -
I have created a rhodes app that connects to a rhosync app when user enters user name and password and clicks on "login". I am calling this webservice through "authenticate" method of application.rb of the rhosync application ..
def authenticate(username,password,session)
Rho::AsyncHttp.get(:url => 'http://mywebserviceURL',:callback => (url_for :action => :httpget_callback),:callback_param => "" )
end
UPDATE
Instead of http:async, I tried consuming a soap based webservice and it worked just fine .. here is code if anyone cones here in search of a sample.. in application.rb of rhosync app
require "soap/rpc/driver"
class Application < Rhosync::Base
class << self
def authenticate(username,password,session)
driver = SOAP::RPC::Driver.new('http://webserviceurl')
driver.add_method('authenticate', 'username', 'password')
ret=driver.authenticate(username,password)
if ret=="Success" then
true
else
false
end
end
end
Application.initializer(ROOT_PATH)
You can typically find the problem if you crank up your log. Edit rhoconfig.txt in your app
set these properties -
# Rhodes runtime properties
MinSeverity = 1
LogToOutput = 1
LogCategories = *
ExcludeLogCategories =
then try again and watch the terminal output. Feel free to post the log back and I'll take a look.
You also might want to echo out puts the mywebserviceURL if you're using that as a variable, I trust you just changed that for the post here. Can you access the webservice if you hit it with a browser?
require "soap/rpc/driver"
class Application < Rhosync::Base
class << self
def authenticate(username,password,session)
driver = SOAP::RPC::Driver.new('http://webserviceurl')
driver.add_method('authenticate', 'username', 'password')
ret=driver.authenticate(username,password)
if ret=="Success" then
true
else
false
end
end
end
Application.initializer(ROOT_PATH)
in this what is done in add_method and authenticate method and where it to be written.