list_comments Ruby implementation with YouTube video_id - ruby

Having trouble implementing the list_comments method in the following code example (n.b. the API is initialised successfully):
# initialize API
service = Google::Apis::YoutubeV3::YouTubeService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
response = service.list_comments('snippet, replies')
Currently the method returns the following error:
missingRequiredParameter: No filter selected. Expected one of: id, idParam, parentId (Google::Apis::ClientError)
I have successfully tested the API call here:
https://developers.google.com/youtube/v3/docs/comments/list
What I'm struggling with is when I test the API call I can pass a videoId to identify a resource, however the method implementation does not allow for this. Could anyone shed some light on how to pass a videoId to the method call?

Found the solution! The method that allows you to specify video_id (or channel_id) to select a specific resource is: list_comment_threads from the Google::Apis::YoutubeV3::YouTubeService module.
response = service.list_comment_threads('snippet', video_id: 'hy1v891n3kA').to_json

Related

Error when creating an FHIR resource in google cloud healthcare API (Ruby)

I'm trying to create a Patient type resource using the service
healthcare = Google::Apis::HealthcareV1
service = healthcare::CloudHealthcareService.new
and create_project_location_dataset_fhir_store_fhir method in ruby.
I keep on getting this error
missing required field: resourceType
more details on the function im using: https://googleapis.dev/ruby/google-api-client/latest/Google/Apis/HealthcareV1/CloudHealthcareService.html#create_project_location_dataset_fhir_store_fhir-instance_method
if anyone has come across this and knows how to fix it
this is how i create my request body:
http_body_object = Google::Apis::HealthcareV1::HttpBody.new
http_body_object.content_type = "application/fhir+json"
http_body_object.data = json_encoded
http_body_object.extensions = extensions
The body could be missing the proper resourceType: Patient as you can find at this link - hl7.org/fhir/patient-example.json.html

Http PUT volley. Parameter in the middle of the url

I am using Volley for my HTTP requests and I have an HTTP put URL which looks like below.
http://mycompany.com/favorite/{roomNumber}/count. I am using a JSON object request. How do I make the API work with the extra "/count" in the API? I am passing the parameter room number in the JSON object.
JSON Object request works fine with this type of URL "http://mycompany.com/favorite/{roomNumber}"
JSON Object request
JsonObjectRequest request = new JsonObjectRequest(METHOD_TYPE_PUT, url, jsonObjectParams, responseListener, errorListener)
Can somebody help me with passing the JSON object parameter in the middle of the URL
Thanks.
You can call the API dynamically like this,
private void getTheApiData(int roomNumber){
JsonObjectRequest request = new JsonObjectRequest(METHOD_TYPE_PUT,
"mycompany.com/favorite" + roomNumber + "/count",
jsonObjectParams, responseListener, errorListener)
}
and call the above API dynamically by the method when you get the new data every time like this.
getTheAPiData(20) //if room number is 20
let me know if you have any issue #Shravani

Adwords API getting customerId

I have an adwords user's Oauth credentials, and I'm able to successfully make an API call to download a report, but I had to hard-code in the customerId as I couldn't figure out how to get it.
The get() method of the CustomerService in the API should return the customer ID, but what are the parameters to pass to it?
I tried a GET request to this URL
without any header params or body params, to which it returns:
"<html><body>No service was found.</body></html>".
I also tried with an Authorization and developerToken defined in the headers, but got the same response.
I also tried the python library, and defined an instance of AdWordsClient like this, but it's client_customer_id variable ends up as None:
from googleads.adwords import AdWordsClient
oauth_client = GoogleRefreshTokenClient(environ.get('GOOGLE_CLIENT_ID'), environ.get('GOOGLE_CLIENT_SECRET'), oauth_record.refresh_token)
adwords_client = AdWordsClient(environ.get('ADWORDS_DEVELOPER_TOKEN'), oauth_client, user_agent='agent'))
customer_id = adwords_client.client_customer_id
print 'customer_id:' + str(customer_id)
Unlike this question, I don't care about adding the user to my MCC account.
Here is how to get the customer ID with the googleads-python-lib library:
oauth_client = GoogleRefreshTokenClient(environ.get('GOOGLE_CLIENT_ID'), environ.get('GOOGLE_CLIENT_SECRET'), oauth_record.refresh_token)
adwords_client = AdWordsClient(environ.get('ADWORDS_DEVELOPER_TOKEN'), oauth_client, user_agent='your_user_agent_here')
customer = adwords_client.GetService('CustomerService').get()
customer_id = customer['customerId']
from googleads import oauth2, adwords
oauth_client = oauth2.GoogleRefreshTokenClient(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, refresh_token)
adwords_client = adwords.AdWordsClient(ADWORDS_DEVELOPER_TOKEN, oauth_client, user_agent='your_user_agent')
customers = adwords_client.GetService('CustomerService', version='v201809').getCustomers()
print(customers['customer_id'])

Making the body of a function use a mock of an object

I have the following method in a controller:
def webhook
data_json = JSON.parse(request.body.read) # it comes from the test, it's OK
event = Stripe::Event.retrieve(data_json[:id]) # it's not OK, it's a real request to Stripe
stripe_cust_id = event.data.object.customer
user = User.where(stripe_customer_id: stripe_cust_id)
#.....
In a spec file I create a mock for event and then make a post request to webhook in a test. I'm not allowed to change the body or signature of webhook because I'm testing it. So how do I make it use the mock I create?
describe '#webhook' do
it 'something' do
user = FactoryGirl.create(:user)
event = StripeMock.mock_webhook_event('invoice.payment_succeeded')
post(:webhook, event.to_json)
#error because webhook makes a real request to Stripe
mock(Stripe::Event).retrieve(any) do
event
end
That should return event from any call to retrieve on Stripe::Event. Works with rr.
If your concern is only about external requests, you can try something like Vcr or WebMock to mock the responce.

How to receive multiple complex objects using HTTP POST method in Web App

I want to call an web api method, this is how my web api method looks like:
[HttpPost]
[Route("PostMyService/updatedBy/{updatedByID}/myobjname")]
public void PostTerminalService([FromBody] List<SomeType> lstSomeObj, MyClass myobj, int updatedByID)
{
//Do Something
}
This is how my client looks like:
int loggedinuserid=1;
List<Sometype> liTS = new List<SomeType>();
MyClass myobj=new MyClass();
var url = "api/XYZ/PostMyService/updatedBy/" + loggedinuserid + "/myobjname/" + myobj;
HttpResponseMessage response = client1.PostAsJsonAsync(url, liTS).Result;
But the error/exception I am getting is:
HTTP Error 404.0 - Not Found
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.
Any idea how to resolve this? I am kind of hitting a wall on this.
Thanks in advance.
You have "api/XYZ/" prefixed in your client code, but I don't see it on your server code. I predict that you have it in your server configuration but if not you will see issues.
You can only have one object with the [FromBody] tag in WebAPI, it's not clear how your trying to pass the MyClass object.
Only simple objects, ints and strings, can be passed in the uri string so the MyClass object will not be transferred correctly.
I would recommend removing the MyClass object or creating a larger object that encapsulates your List<SomeType> andMyClass` and pass that in the body of the request with the [FromBody] decoration.
Here's more information on the topic

Resources