Koala gem get_object returns GraphMethodException - ruby-on-rails

I'm using the Koala gem to get metrics (likes, comments, and shares) on Facebook posts. I literally have not touched the Koala code in months, yet is suddenly stopped working. I'm able to get likes and comments, but not shares. I checked the docs for the gem as well as the issues on GitHub and didn't see anything related to my issue. Not sure if it's my code or the gem or a change to Facebook's API.
I have the following method, which is called by another method, which is responsible for updating all metrics on the post.
def call_facebook_api(client, method, pid, metric)
resp = client.method(method).call(pid, metric)
rescue Koala::Facebook::ClientError => e
puts "Rescue from #{e}"
puts "Method: #{method}"
puts "Metric: #{metric}"
puts "Post ID: #{pid}"
return nil
end
Here are some sample values for the method arguments:
client
=> #<Koala::Facebook::API:0x007fbbfdf25dd0 #access_token="super_secret",#app_secret="super_duper_secret">
method
=> :get_object
pid
=> "202001613484188_1142111705834093"
metric
=> {:fields=>["shares"]}
When I run the method above with these inputs it returns this error:
Koala::Facebook::ClientError: type: GraphMethodException, code: 100, message: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api [HTTP 400]
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/koala-2.2.0/lib/koala/api/graph_api.rb:515:in `block in graph_call'
I've also tried the following combinations unsuccessfully:
client.get_object(pid)
client.get_object(pid, fields: ['shares'])
client.get_object(pid, 'shares')
client.get_object("#{pid}/sharedposts")
client.get_object("#{pid}?fields=sharedposts")
client.get_object("#{pid}?fields=shared")
client.get_object("#{pid}?fields=shares")
client.get_connections(pid)
client.get_connections(pid, 'shares')
client.get_connections("#{pid}/sharedposts")
Referencing the Graph API docs hasn't given me any new insights into the problem.
As I said before, I haven't touched the above code in months, yet it only recently stopped working. I did recently upgrade my Rails app from 4.06 to 4.2.5.1. I also upgraded from Ruby 2.0.0 to 2.3.0. I did not upgrade the Koala gem though. I was already running 2.2.0 (latest).

Related

ActiveMerchant Cybersource Authorization Error Reason 102

I'm work on debugging an application that is currently running on Ruby 2.5.8 with ActiveMerchant 1.117.0.
I am able to create and save the subscription successfully. However, when I try to authorize the saved card I keep getting reasonCode 102. The error from the Cybersource gateway side is the subscription () could not be found.
I'm attempting to authorize with the function:
def authorize(token, amount, order_id, line_items)
response = gateway.authorize(amount, token, order_id: order_id, line_items: line_items)
if !response.success?
raise Exceptions::ChargeFailed.new(response.message, response: response)
end
response
end
The error would lead me to believe that the formatting here is not correct. Can anyone point me to some working ActiveMerchant CyberSource examples for authorizing a subscription or point out what might be wrong here?
After some digging, it appears that the logic for token assignment changed inside of the ActiveMerchant CyberSource gem
The original logic was:
if reference
_, subscription_id, _ = reference.split(";")
xml.tag! 'subscriptionID', subscription_id
end
The latest versions this shifted towards:
if reference
subscription_id = reference.split(";")[6]
xml.tag! 'subscriptionID', subscription_id
end
The application that I am working with previously had been formatting the CyberSource profile / subscription id as ;#{token};. In order to work with these latest updates the token needs to be formatted as ;;;;;;#{token}.

Ruby Google Cloud PubSub async pull returns GRPC::DeadlineExceeded error

Hi I have a subscription set up in Google PubSub and I am trying to pull messages asynchronously using the "official" google-cloud-ruby library. Here is my code which will be executed from a rake task which passes in subscription_name:
def pull!
creds = Google::Cloud::PubSub::Credentials.new(
GCP_CREDENTIALS_KEYFILE_PATH,
scope: "https://www.googleapis.com/auth/pubsub"
)
messages = []
pubsub = Google::Cloud::PubSub.new(
project_id: GOOGLE_PROJECT_ID,
credentials: creds
)
subscription = pubsub.subscription(subscription_name)
subscription.pull(immediate: true).each do |received_message|
puts "Received message: #{received_message.data}"
received_message.acknowledge!
messages.push(received_message)
end
# Return the collected messages
messages
rescue => error
Rails.logger error
messages.presence
end
The Google::Cloud::PubSub::Credentials part references a working keyfile. I know the JSON keyfile is good since I can use it to generate a working Bearer token using oauth2l and pull from the PubSub using cURL, postman, Net::HTTP, etc. Using the same JSON credentials for a separate Google::Cloud::Storage service and that works fine also.
But for some reason using Google::Cloud::PubSub it just hangs and won't respond. After about 60 seconds I get the following error:
GRPC::DeadlineExceeded: 4:Deadline Exceeded. debug_error_string:{"created":"#1602610740.445195000","description":"Deadline Exceeded","file":"src/core/ext/filters/deadline/deadline_filter.cc","file_line":69,"grpc_status":4}
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:29:in `check_status'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:180:in `attach_status_results_and_complete_call'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:376:in `request_response'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/client_stub.rb:172:in `block (2 levels) in request_response'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/interceptors.rb:170:in `intercept!'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.32.0-universal-darwin/src/ruby/lib/grpc/generic/client_stub.rb:171:in `block in request_response'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/gapic-common-0.3.4/lib/gapic/grpc/service_stub/rpc_call.rb:121:in `call'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/gapic-common-0.3.4/lib/gapic/grpc/service_stub.rb:156:in `call_rpc'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/google-cloud-pubsub-v1-0.1.2/lib/google/cloud/pubsub/v1/subscriber/client.rb:503:in `get_subscription'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/google-cloud-pubsub-2.1.0/lib/google/cloud/pubsub/service.rb:154:in `get_subscription'
/Users/bbulpet/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/google-cloud-pubsub-2.1.0/lib/google/cloud/pubsub/project.rb:286:in `subscription'
Adding a debugger shows that the following line is what hangs and results in an error:
subscription = pubsub.subscription(subscription_name)
I've tried everything I can think of based on the documentation. Updated all related gems and even tried using deprecated syntax out of desparation. If anyone has at least an idea of where to start that would be most appreciated, thanks!
UPDATE
So it turns out that for some reason running this locally was not able to connect, but when shipped to a deployed environment the above code connected flawlessly to pubsub and was able to pull and ack messages. Further, upon making the initial connection in the deployed environment, I am now able to connect locally as well using the same credentials.
Link to Github issue conversation for context around the troubleshooting process and quartzmo suggestion to try deploying to another environment.
Are you still having this issue? I just tried to reproduce it using Ruby 2.6.5p114, google-cloud-pubsub 2.1.0 and grpc 1.32.0 (same versions as you), but I cannot reproduce it. Here is my code (slightly modified to run in a Minitest spec context) for comparison:
GCP_CREDENTIALS_KEYFILE_PATH = "/Users/quartzmo/my-project.json"
GOOGLE_PROJECT_ID = "my-project-id"
def pull! topic_name, subscription_name
creds = Google::Cloud::PubSub::Credentials.new(
GCP_CREDENTIALS_KEYFILE_PATH,
scope: "https://www.googleapis.com/auth/pubsub"
)
messages = []
pubsub = Google::Cloud::PubSub.new(
project_id: GOOGLE_PROJECT_ID,
credentials: creds
)
topic = pubsub.create_topic topic_name
topic.subscribe subscription_name
topic.publish "A test message from #{topic_name} to #{subscription_name}"
subscription = pubsub.subscription(subscription_name)
subscription.pull(immediate: true).each do |received_message|
puts "Received message: #{received_message.data}"
received_message.acknowledge!
messages.push(received_message)
end
# Return the collected messages
messages
end
focus
it "pull!" do
topic_name = random_topic_name
subscription_name = random_subscription_name
messages = pull! topic_name, subscription_name
assert_equal 1, messages.count
assert_equal "A test message from #{topic_name} to #{subscription_name}", messages[0].data
end
And this is the output:
% bundle exec rake test
Run options: --junit --junit-filename=sponge_log.xml --seed 30984
# Running:
Received message: A test message from ruby-pubsub-samples-test-topic-7cb10bde to ruby-pubsub-samples-test-subscription-f47f2eaa
.
Finished in 6.529219s, 0.1532 runs/s, 0.3063 assertions/s.
1 runs, 2 assertions, 0 failures, 0 errors, 0 skips
Update (2020-10-20): This issue was resolved when executing the code in a different environment, although the reason is unknown. See comment on GitHub issue.

Docusign gem block request

I'm using the DocuSign ruby client (https://github.com/docusign/docusign-ruby-client) on ruby on rails to send a document via email to some clients, but when I deploy the project after 15 minutes the request between the application and DocuSign gets "paused". For some reason the gem creates the request but doesn't send it as you can see in the next image where I enable the debug in the gem:
In that point the log doesn't print any more after 15 minutes.
The code that send the message in my app is:
access_token = "xxxxxxx"
account_id = "xxxxxxxxx"
base_path = "xxxxxxxxxx"
envelope_args = {
signer_email: contact.email,
signer_name: contact.name,
template_id: document.docusign_id
}
#args = {
account_id: account_id,
base_path: base_path,
access_token: access_token,
envelope_args: envelope_args
}
envelope_args = #args[:envelope_args]
# 1. Create the envelope request object
envelope_definition = make_envelope(envelope_args)
# 2. Call Envelopes::create API method
# Exceptions will be caught by the calling function
envelope_api = create_envelope_api(#args)
envelope_api.create_envelope #args[:account_id], envelope_definition
I don't know what can I do.
Thank you
Your screenshot shows everything happening at 18:29:05 -- I don't understand the issue.
Also, have you tried install/using the RoR code example?
See if it has the same problem.
We looked for the issue in our code, but we saw that in the step which the request is send in the gem here always freezes. So we debugged there and we saw that curl was being used for ruby. At that point we saw that curl was trying to reconnect with Docusign but it wasn't success, so we found this issue in the version of curl that we had (https://github.com/curl/curl/issues/4499 )
To fix it we updated the version to the latest, and it fixed the issue.
Thanks for your answers.

Why do I get the error 'HTTP Response: 403 Forbidden' when I try to call the amazon api in my Rails app?

I'm creating a Ruby on Rails application and am following the instructions step for step based on the gem required to call the amazon API (https://github.com/jugend/amazon-ecs) when searching for an item.
This is my code in the Ruby app:
Amazon::Ecs.options = {
:associate_tag => '[*****]',
:AWS_access_key_id => '[*****]',
:AWS_secret_key => '[*****]'
}
res = Amazon::Ecs.item_search('soccer books')
puts res.total_items
I've tried regenerating my keys, still doesn't work and am not sure what to do.
It might be possible issue in gem as they already solved if for 1.9 . You can check changelog here https://github.com/jugend/amazon-ecs/blob/master/CHANGELOG . This confirm that issue resolved for 1.9 . But might be come up again due to new changes they done. So my opinion is to create an issue in gem as well.
please check s3-bucket timestamp and you local machine timestamp. If its greate the 10hr or more s3 considers as invalid request and refuse it.

Issue in generating invoice using Stripe api

I have integrated stripe API in my Rails application. I am facing a problem while getting invoiceitems from the JSON object.
Here i have provide you the details.
OS: CentOS
Ruby: v1.9.3
Rails: v3.0
Stripe: v1.8.3
cus_invoices = Stripe::Invoice.all(:customer=>customer.id, :count=>1).data
cus_invoices.each do |invoices|
invoiceitems = invoices.lines.invoiceitems.each do |lineitems|
Here, the transaction got successful and while returning the stripe ListObject, it throws an error as follows.
CLASS_NAME: NoMethodError
MESSAGE: undefined method invoiceitems' for #<Stripe::ListObject:0xbd9b13c>
TRACE: /usr/local/lib/ruby/gems/1.9.1/gems/stripe-1.8.3/lib/stripe/stripe_object.rb:148:inmethod_missing'
I didn't face this issue previously. Please let me know if any change in JSON object structure.
Kindly provide your support to solve this issue.
Thanks,
Jude
https://stripe.com/docs/api#list_customer_invoices shows the json
invoices.lines.each do |line|
line_item = line.data
line_item.id
line_item.amount
end
You should check your API version (https://stripe.com/docs/api#versioning). If Stripe makes backward incompatible changes, it ups the API version.
Stripe sets the API version based on when you first use the API. So, if you recently got new API keys, it could use a new API version than when you originally started using it.
You can change your API version in your config initializer. Example:
Stripe.api_version = "2013-02-13"

Resources