Yahoo gemini Get job status - yahoo-api

Im following this link
i have successfully got this result:
{
"errors": null,
"response": {
"jobId": "628cf1c0cd1c5d8a6c1765f618b7a0be34c50bc1564618",
"status": "submitted",
"jobResponse": null
}
}
ant tried GET call to check the status of the job , exactly as they are asking
https://api.admanager.yahoo.com/v1/rest/reports/custom/628cf1c0cd1c5d8a6c1765f618b7a0be34c50bc1564618?access_token=&advertiserId=21
but i get an error massage :
<?xml version="1.0" encoding="UTF-8"?>
-
Please provide valid credentials. OAuth oauth_problem="unable_to_determine_oauth_type", realm="yahooapis.com"
what am i doing wrong ?
i have even tried adding the access token

Yahoo API wasn't that precise beside the fact they had some system maintenance
this is how the url for testing if job has finished:
String urlToCheckIfDownloadReady = "https://api.admanager.yahoo.com/v1/rest/reports/custom/" + jobId + "?access_token=" + refreshToken + "&advertiserId=" + config.mccCustomerId;
if status = completed
Get from the Json response the jobResponse and than download it

Related

RESTful client in Unity - validation error

I have a RESTful server created with ASP.Net and am trying to connect to it with the use of a RESTful client from Unity. GET works perfectly, however I am getting a validation error when sending a POST request. At the same time both GET and POST work when sending requests from Postman.
My Server:
[HttpPost]
public IActionResult Create(User user){
Console.WriteLine("***POST***");
Console.WriteLine(user.Id+", "+user.sex+", "+user.age);
if(!ModelState.IsValid)
return BadRequest(ModelState);
_context.Users.Add(user);
_context.SaveChanges();
return CreatedAtRoute("GetUser", new { id = user.Id }, user);
}
My client:
IEnumerator PostRequest(string uri, User user){
string u = JsonUtility.ToJson(user);
Debug.Log(u);
using (UnityWebRequest webRequest = UnityWebRequest.Post(uri, u)){
webRequest.SetRequestHeader("Content-Type","application/json");
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
if (webRequest.isNetworkError || webRequest.isHttpError){
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
}
else{
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
}
}
}
I was trying both with the Json conversion and writing the string on my own, also with the WWWForm, but the error stays.
The error says that it's an unknown HTTP error. When printing the returned text it says:
"One or more validation errors occurred.","status":400,"traceId":"|b95d39b7-4b773429a8f72b3c.","errors":{"$":["'%' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0."]}}
On the server side it recognizes the correct method and controller, however, it doesn't even get to the first line of the method (Console.WriteLine). Then it says: "Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'".
Here're all of the server side messages:
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 POST http://localhost:5001/user application/json 53
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'TheNewestDbConnect.Controllers.UserController.Create (TheNewestDbConnect)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "Create", controller = "User"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Create(TheNewestDbConnect.Data.Entities.User) on controller TheNewestDbConnect.Controllers.UserController (TheNewestDbConnect).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action TheNewestDbConnect.Controllers.UserController.Create (TheNewestDbConnect) in 6.680400000000001ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'TheNewestDbConnect.Controllers.UserController.Create (TheNewestDbConnect)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 11.3971ms 400 application/problem+json; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
I have no idea what is happening and how to solve it. Any help will be strongly appreciated!
Turned out I was just missing an upload handler. Adding this line solved it: webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(JsonObject));

How to access custom header from AWS Lambda Authorizer?

I have created an Authorizer in AWS API Gateway. This Authorizer refers to a Lambda Function.
I am passing the following values in header, to the API Endpoint using Postman.
{
"type":"TOKEN",
"authorizationToken": "testing2",
"methodArn": "arn:aws:execute-api:us-west-2:444456789012:ymy8tbxw7b/*/GET/"
}
The above header values are received in the Lambda Function. I can see this through the logs in CloudWatch.
I want to pass additional value 'clientID' in the header. So I pass the following values in the header from postman.
{
"type":"TOKEN",
"authorizationToken": "testing2",
"methodArn": "arn:aws:execute-api:us-west-2:123456789012:ymy8tbxw7b/*/GET/",
"clientID" : "1000"
}
In this case, the Lambda function does not get the clientID. I checked various threads in SO, and understood that this can be achieved mapping header. So I did the following.
In the "Method Execution" section of the API method, I created a new header clientID. In the "Integration Request" section, under "HTTP Headers" section I provided the following value
Name: clientID
Mapped from: method.request.header.clientID
After doing the above, I deployed the API and tried to call the method from Postman, but the clientID is shown undefined. Following is the code that I have written in Lambda Function
exports.handler = function(event, context, callback) {
var clientid = event.clientID;
//I always get event.clientID undefined
console.log("The client ID is:" + event.clientID);
}
EDIT
Following is the error from the CloudWatch Log.
START RequestId: 274c6574-dea5-4009-b777-a929f84b9a9d Version: $LATEST
2019-09-19T09:40:25.944Z 274c6574-dea5-4009-b777-a929f84b9a9d INFO The client ID is:undefined
2019-09-19T09:40:25.968Z 274c6574-dea5-4009-b777-a929f84b9a9d ERROR Invoke Error
{
"errorType": "Error",
"errorMessage": "Unauthorized",
"stack": [
"Error: Unauthorized",
" at _homogeneousError (/var/runtime/CallbackContext.js:13:12)",
" at postError (/var/runtime/CallbackContext.js:30:51)",
" at callback (/var/runtime/CallbackContext.js:42:7)",
" at /var/runtime/CallbackContext.js:105:16",
" at Runtime.exports.handler (/var/task/index.js:40:4)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
I have understood why I was not getting the value in the header. I have done the following
1) Instead of type TOKEN, I used type REQUEST in the header. I understood this by reading the following link. This link also contains code for Request type.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html
2) I removed all the mapping from Method Request and Integration Request.
3) Deployed the API.

Backend Error (HttpError 500) on Google Search Console API calls (webmasters/v3)

I prepared code that should fetch data from google webmaster console new Web API (v3).
import os
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
from apiclient.discovery import build
import googleapiclient
import json
client_email = '<ACCOUNT_IDENTIFIER>#<PROJECT_IDENTIFIER>.iam.gserviceaccount.com'
scopes = ['https://www.googleapis.com/auth/webmasters.readonly',
'https://www.googleapis.com/auth/webmasters']
private_key_path = os.getcwd() + os.path.normpath('/key.p12')
http = httplib2.Http()
credentials = ServiceAccountCredentials.from_p12_keyfile(client_email,
private_key_path,
private_key_password="notasecret",
scopes=scopes
)
http_auth = credentials.authorize(http)
webmasters_service = build('webmasters', 'v3', credentials=credentials, http=http_auth)
query_params = {"startDate": "2016-03-01", "endDate": "2016-03-02"}
try:
quered_results = webmasters_service.searchanalytics().query(
key="<KEY>",
siteUrl="http://<SITE_DOMAIN>/",
body=json.dumps(query_params),
fields="rows",
alt="json"
).execute()
print(quered_results)
except googleapiclient.errors.HttpError as e:
print(e)
Execution results with error:
<HttpError 500 when requesting https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2F<SITE_DOMAIN>%2F/searchAnalytics/query?key=<KEY>&alt=json&fields=rows returned "Backend Error"
The code from above is for authorization with ssh key with p12 format. Key file is correct. Using client_secrets.json end up with the same error, code. The json for error is:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error",
}
],
"code": 500,
"message": "Backend Error"
}
}
I did connect email to webmaster tools console.
Authorization seems to work since there is no errors for used key/account
Any ideas?
I've noticed that the same error occures when I fetch on https://developers.google.com/apis-explorer with "Request body" improperly set, but I do not see error in JSON I send. BTW It would be nice to have some validation message about that...
Found it! body parameter should actually by python object, not JSON formatted string!
body=json.dumps(query_params),
Should be
body=query_params,

facebook api in R: OAuthException error, code 803

Im trying to connect to Facebook using R. I tried to use the codes from
https://github.com/datamgmt/facebook-data-mining
Which gets the user information with the following code:
access.token<- "AAACE________n6bcITRIMCZCKhMySOV" #my access token
FacebookFetch <- function(access.path = "me", access.token, access.options) {
if (missing(access.options)) {
access.options <- ""
}
else {
access.options <- sprintf("?%s", paste(names(access.options), "=",
unlist(access.options), collapse = "&", sep = ""))
}
data <- getURL(sprintf("https://graph.facebook.com/%s%s&access_token=%s",
access.path, access.options, access.token),cainfo="cacert.pem")
fromJSON(data)
}
individual.id <- "100__72" # my ID
individual <- FacebookFetch(access.path=paste(individual.id),access.token=access.token )
if (length(individual$id)) {
cat ("Working with individual: ",individual$name," (",individual$id,")\n", sep="")
} else{
cat("Message: ", unlist(individual)[1], "\n")
cat("Type: ", unlist(individual)[2], "\n")
cat("Code: ", unlist(individual)[3], "\n")
stop(" Cannot continue")
}
where cainfo="cacert.pem" is added to work around the SSL certificate verification error.
Although now I get the following error and I have no idea how to solve this.
Message: (#803) Some of the aliases you requested do not exist: 100__72&access_token=AAACE________n6bcITRIMCZCKhMySOV
Type: OAuthException
Code: 803
I found some posts where people got the same problem, only not using R but other programs, the problem was fixed by making the token and id a character. However, in R, these are already of class character.
When im recreating the url in the browser it returns the same error, while the graph explorer returns all the correct information. I have tried to refresh the token multiple times, but that didn't work.
The API reference book doesn't state what error code 803 entails.
does anybody have an idea how to solve this?
Im using r 2.15.2 in Rstudio on a windows 7 pro (also tried it on windows vista)

google apps script soap client without wsdl

I am attempting to access the Numara Footprints web services API from google apps script. There is no wsdl for the web service, but the methods are well documented. All of the examples of using Google Apps Script Soap Service assume the existence of a wsdl file, which makes it a non-starter for my purposes. So I am trying to use UrlFetchApp instead. By using the sample php code that Numara Footprints provides, I established what the request should look like, and wrote the following code in google apps script:
function sendHttpPost() {
var payload= '<?xml version="1.0" encoding="utf-8"?>' +
'<SOAP-ENV:Envelope'+
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
'xmlns:ns1="MRWebServices"'+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"' +
'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
'<SOAP-ENV:Body>'+
'<ns1:MRWebServices__search>'+
'<param0 xsi:type="xsd:string">ACCOUNT NAME</param0>'+
'<param1 xsi:type="xsd:string">PASSWORD</param1>'+
'<param2 xsi:type="xsd:string"></param2>'+
'<param3 xsi:type="xsd:string">'+
"SELECT * from MASTER1 where mrid='16888'</param3>"+
'</ns1:MRWebServices__search>'+
'</SOAP-ENV:Body>'+
'</SOAP-ENV:Envelope>';
var headers =
{
"SOAPAction" :encodeURIComponent("MRWebServices#MRWebServices__search")
};
var options =
{
"contentType": "text/xml; charset=utf-8",
"method" : "post",
"headers" : headers,
"payload" : payload
};
UrlFetchApp.fetch("http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl", options);
}
This code contacts the server successfully and gets the following error message returned:
Request failed for http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl
returned code 500. Server response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Application failed during request deserialization:
not well-formed (invalid token) at line 1, column 70, byte 70 at
C:/FootPrints/bin/Perl/lib/XML/Parser.pm line 187 </faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> (line 40)
I don't know of any way to get more detailed error messages, and I don't know what the problem is. The xml that I am sending is copied directly from the PHP code that works perfectly.
I'm wondering if anyone either:
can see a problem with the google apps script code above or
can tell me how to use the Google Apps Script soap service when I don't have a wsdl file or
knows of a way to get a web service to return more error details.
Thanks in advance. I've looked everywhere that I can think of but not found an answer.
The payload var in the above code needed spaces between the XML elements. Corrected code (note spaces at the end of each line):
var payload= '<?xml version="1.0" encoding="utf-8"?> ' +
'<SOAP-ENV:Envelope '+
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:ns1="MRWebServices" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" ' +
'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> '+
'<SOAP-ENV:Body> '+
'<ns1:MRWebServices__search> '+
'<param0 xsi:type="xsd:string">ACCOUNT NAME</param0> '+
'<param1 xsi:type="xsd:string">PASSWORD</param1> '+
'<param2 xsi:type="xsd:string"></param2> '+
'<param3 xsi:type="xsd:string"> '+
"SELECT * from MASTER22 where mrid='16888'</param3> "+
'</ns1:MRWebServices__search> '+
'</SOAP-ENV:Body> '+
'</SOAP-ENV:Envelope>';
Also, in the headers, I did not need to use encodeURIComponent(). Corrected code:
var headers =
{
"SOAPAction" :"MRWebServices#MRWebServices__search"
};