Yandex API Translator error - 401 API key is invalid - coldfusion

I registered with Yandex and got a Translate API Key. However when I try to translate with the following code:
<CFSET Key = "trnsl.1.1.2014091...........................">
<CFSET lang="en-de">
<CFSET text="Hallo World">
<CFHTTP URL="https://translate.yandex.net/api/v1.5/tr.json/translate?Key=#Key#&lang=#lang#&text=#text#" METHOD = "GET">
</CFHTTP>
<CFOUTPUT>#CFHTTP.FileContent#</CFOUTPUT>
I get a 401 error "API key is invalid". I also tried with Javascript/CFML but got a similar result. I have checked the key, and it is current.
Anyone got something similar working?

?Key=#Key#&lang=#lang#&text=#text#
This is going to sound a little crazy, but .. I think the reason is that the url parameter names are case sensitive. Since you are using ?Key= instead of ?key (all lower case) the receiving end thinks you did not supply an API key - at all. Hence the error. (Though "missing or invalid key" would be a little more accurate).
Try using ?key= (all lower case) instead and it should work.

Related

Getting gskey: request denied

Hey trying to insert and update a list items on one of my tabs but i'm getting the error msg "gskey: request denied error".
I don't understand what this error means. Can someone please clarify what would be the cause for this error.
A call to the checkgskey function on the server side gives the "gskey: request denied" error if the X-GSREQ-KEY in the POST request is missing.
X-GSREQ-KEY is automatically transmitted by a dedicated parameter in either ajxpgn or reload tab. The content of the gskey is output by the emitgskey function.
emitgskey('unique_phrase');
checkgskey('unique_phrase');
As long as the two unique phrases match, the request is not blocked. The unique phrase acts as a seed to compute a protective challenge that's unique to the user, session and location. In a way, the purpose of a GSKey is similar to a nounce.
Additional documentation here.
Turns out the gskey wasn't being passed in with the call. You get that error when there's a key expected but not given.

Vimeo OAuth Error - he consumer key passed was not valid

Am trying to get authenticated with the API and it is saying "The consumer key passed was not valid." msg="Invalid consumer key". Before that it was saying that the oauth_signature is invalid and I have struggled for a day with it and now that error is not showing up. Please find my code in the above gist.
You help is much appreciated on this.
There are a handful of reasons that you might see this error, all of which mean that your oauth 1.0a protocol is likely incorrect.
I highly recommend you test your app alongside this tool : http://hueniverse.com/oauth/guide/authentication/
Below are the important steps to check.
Compare your base string to the Hueniverse base string. If they match, you are likely signing incorrectly. If they do not match make sure you are sorting the parameter keys properly
If the base string matches, check your signature method and your signing process. The secret of your request should be client_secret& OR client_secret&token_secret. Note the ampersand always exists.

ACCESS_DENIED Status from Places API

I'm developing an Android App that uses the Places API to retrieve information and displays it on a map. The initial request to retrieve to places fails with a ACCESS_DENIED status message from the HTTP request. Below is the code that I used to generate the request:
try {
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory
.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
request.getUrl().put("key", API_KEY);
request.getUrl().put("location", _latitude + "," + _longitude);
request.getUrl().put("radius", _radius); // in meters
request.getUrl().put("sensor", "false");
if(types != null)
request.getUrl().put("types", types);
PlacesList list = request.execute().parseAs(PlacesList.class);
// Check log cat for places response status
Log.d("Places Status", "" + list.status);
return list;
In another Stackoverflow posting someone had suggested that the poster try the following to test their key:
Go to the api console here, then to SERVICES. Click Active services
tab and verify 'Places API' is turned ON. Click on the ? "try" link
next to it. It should create a proper URL with your key which should
work. Compare the link that you are trying against this URL for
differences.
I followed these instructions. Based on the fact that I received the following results when I clicked on the ? to "try" the link I suspect something is fundamentally wrong with the API Key independent of the code...otherwise I would think I would get a SUCCESS rather than REQUEST_DENIED:
{
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
I obtained my key by entering the SHA1 of my debug certificate (which i obtained using Keytool with all the appropriate parameters...e.g, androiddebugkey....debug.keystore) followed by a ";" and the Package Name of the app.
Not sure what the problem is...I'm sure it's something simple but I'm not seeing it and I'm stuck. Thoughts?
I never received a response to this posting so ultimately I've resolved the problem by creating a brand new key under a new project name and I was at least able to retrieve Places from Google..I'm still having issues with populating maps but that could be a code issue.
I noticed that the key that I was using that gave me the ACCESS DENIED results had a title of: "Key for Android apps (with certificates)" and it had a label "Android apps:" listed just under the actual key. The key value is the SHA1 value ";" followed by the Package Name. Whereas the key I created under a new Project Name (Places API) that ultimately worked had a title of: "Key for browser apps (with referers)" and it had a label of "Referers:" and value of "Any referer allowed".
So there is definitely something different about these two keys. I'm not sure what I did differently when I generated the keys. I'd like to understand what I did to generate these two "different" types of keys so that I and perhaps others won't repeat my "mistake(s)".
There are many references to creating keys in the Google documentation. The fact that there are so many postings regarding problems with the keys tells me that the Google documentation is not very clear otherwise so many issues wouldn't exist on this topic.

coldfusion making better use of cfparam

In our index files, at the top of the file we will generally <cfparam> out the variables that will come from the URL, form or wherever. However, we are getting a lot of bots hitting us with things like www.example.com/survey/index.cfm?nPageNumber=-1 meaning a cfparam like this:
<cfparam name="request.parameters.nPageNumber" default="1" type="numeric" />
will fail due to the nonsense a bot is putting into the querystring.
I find myself increasingly having to write my cfparams like this:
<cfif structKeyExists(request.parameters,"nPageNumber") AND isNumeric(request.parameters.nPageNumber)>
<cfparam name="request.parameters.nPageNumber" default="1" type="numeric" />
<cfelse>
<cfset request.parameters.nPageNumber = 1>
</cfif>
While this solves the issue, I can't help but feel this solution is not the best/most efficient. Am I using cfparam correctly or are there better ways of doing this?
Ensuring the existence of a variable, and validating its value are two separate tasks.
In the case of URL and Form your existence code should be something like:
<cfparam name="URL.nPageNumber" default="1" type="string">
The use of type there is just to ensure that nothing truly bizarre has happened such as the value is a struct or query, etc. You don't want to get specific at this point since you want a graceful error and not at 500 for the user.
Once you've made sure that the value exists, you then need to validate the value.
<cfif isNumeric(URL.nPageNumber) EQ false OR URL.nPageNumber LT 1 OR URL.nPageNumber GT Variables.MaxPages>
<cfset ArrayAppend(Variables.ErrorArray, "Incorrect page number requested.")>
</cfif>
You could force the value to something sane, but see Martian Headsets for a counter argument to the robustness principle.
Providing an error message instead of "displaying something sane" will inform your users that they are doing something wrong, and means you're not forced to use canonical urls if you're not already (although you should be).
Yes, it's more work. You can devise some abstraction for it all, but at the raw level, that's what you should be doing with your cfparams and validation.
In the situation where you don't need to have a friendly response, such as a bot or a request that is obviously a hack or probing, there's the additional option to serve a "400" response code. The w3c defines the response as "The request had bad syntax or was inherently impossible to be satisfied." here and "The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications." here.

django + confusion with the ORM

I am getting a strange error despite following the documentation. I have the following model:
class UserToken(models.Model):
token = models.CharField(max_length=100)
user = models.ForeignKey(User)
Whenever I do UserToken.objects.get(token=tokenValue) (tokenValue is the value I am looking for) locally for MySQL, everything works. I get the value as expected. But when I do the same on my MySQL instance in Amazon RDS, I keep getting the following error:
ERROR Unknown exception: UserToken matching query does not exist.
Is there anything I am missing here? Why would a statement like this not work in RDS?
[EDIT]
Just to clarify, the token values do indeed exist. I checked the database just to make sure. Also I tried the following:
ut = UserToken.objects.raw("select * from user_token") (just to test..there was only one entry in the table) and i'm getting the following error: Unknown exception: 'RawQuerySet' object has no attribute 'token'. Is there a reason for this? The token field does exist.
I'm really not sure how this is different...but previously I was doing request.raw_post_data to get the json message that the user was sending me. I changed that to request.POST and request.body and somehow that fixed the issue. Just in case anybody else faces this hard-to-debug issue!