systemapks.variants.download doesn't pop up any error message and download anything - google-apis-explorer

After execute create method, use valid variantId to execute request as "https://developers.google.com/android-publisher/api-ref/rest/v3/systemapks.variants/download" suggested, no error pops up and nothing is downloaded.
service = build('androidpublisher', 'v3', http=http_auth, cache_discovery=False)
variant = service.systemapks().variants().download(packageName=package_name, versionCode=version_code, variantId=variant_id).execute()

You should add "&alt=media" to the URL, like this:
https://www.googleapis.com/androidpublisher/v3/applications/<package_name>/systemAPKs/<version_code>/variants/<variant_id>:download?alt=media
Then the request body will contain the binary of the APK.

Related

JSON.parse returning undefined object

Blizzard just shut down their old API, and made a change so you need an apikey. I changed the URL to the new api, and added the API key. I know that the URL is valid.
var toonJSON = UrlFetchApp.fetch("eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items,statistics,progression,talents,audit&apikey="+apiKey, {muteHttpExceptions: true})
var toon = JSON.parse(toonJSON.getContentText())
JSON.pase returns just an empty object
return toon.toSorce() // retuned ({})
I used alot of time to see if i could find the problem. have come up empty. Think it has something to do with the "responce headers".
Responce headers: http://pastebin.com/t30giRK1 (i got them from dev.battle.net (blizzards api site)
JSON: http://pastebin.com/CPam4syG
I think it is the code you're using.
I was able to Parse it by opening the raw url of your pastebin JSON http://pastebin.com/raw/CPam4syG
And using the following code
var text = document.getElementsByTagName('pre')[0].innerHTML;
var parse = JSON.parse(text);
So to conclude I think it is the UrlFetchApp.fetch that's returning {}
So i found the problems:
I needed https:// in the URL since i found after some hours that i had an SSL error
If you just use toString instead of getContentText it works. Thow why getContentText do not work, i am not sure of.
was same problem, this works for me (dont forget to paste your key)
var toonJSON = UrlFetchApp.fetch("https://eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items%2Cstatistics%2Cprogression%2Caudit&locale=en_GB&apikey= ... ")

JSON encoding error publishing SNS message with Boto 3

I am trying to send a simple JSON message to an Amazon SNS topic in Boto 3. However, I keep getting a _jsonparsefailure in the tag of the message and I only receive the default value. Here is my code:
mess = {'default': 'default', 'this': 'that'}
jmess = json.JSONEncoder().encode(mess)
response = self.boto_client.publish(
TopicArn = self.TopicArn,
MessageStructure = 'json',
Message = jmess
)
I have also tried json.dumps(), which produces the same result.
mess = {'default': 'default', 'this': 'that'}
jmess = json.dumps(mess)
response = self.boto_client.publish(
TopicArn = self.TopicArn,
MessageStructure = 'json',
Message = jmess
)
I seem to be following all of the guidelines set by the documentation, and I'm not getting an exception when I run the script. There are SQS queues that subscribe to the topic, and I am pulling the result data straight from the console.
This is how I fixed it:
message = {"record_id": "my_id", "name": "value"}
json_message = json.dumps({"default":json.dumps(message)})
sns_client.publish("topic_arn", Subject="test", MessageStructure="json", Message=json_message)
SNS expects "default" as the key which contains the message to be published.
It turns out the message needs to look like this:
json.dumps({"default": "my default", "sqs": json.dumps({"this": "that"})})
Amazon has horrible documentation in this regard.
You can also remove the MessageStructure='json'and send just json.dumps({'this':'that'}) if you set the SQS queue to receive just the raw message. This is simply done through the console.
In Boto 3 (I'm using v1.4.7) this is the format:
sns.publish(TopicArn="topic_arn", Message=json.dumps({"this": "that"},ensure_ascii=False))
There isn't any need for the protocol definition, i.e. "default" unless you are delivering different structures per protocol, i.e., JSON for Lambda and HTML for email.

jsonp error with .json extension

I am using jsonp to get an external json file from the cloud. I may be being stupid but if I use this file it throws an error but works if I use a file like http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts
The json also works if I pull it in locally
function AppGuides($scope, $http) {
var url = "http://keystone-project.s3.amazonaws.com/assets/documents/AirFrance.json?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(function(data){
$scope.guidedata = data;
console.log('success');
})
.error(function () {
console.log('error');
});
$scope.ddSelectSelected = {
Label: "Select an Option",
class: "hidden"
};
}
UPDATE WITH FIDDLE
http://jsfiddle.net/ktcle/a4Rc2/953/
After closer inspection and trying the code out myself, I can tell you the error is not in this angular application, but with the server where we try to download the JSON.
A simple GET request to http://keystone-project.s3.amazonaws.com/assets/documents/AirFrance.json?callback=JSON_CALLBACK reveals that the Content-Type of the returned data is application/x-unknown-content-type, when it should be application/json.
The exact error it raises is
Resource interpreted as Script but transferred with MIME type application/x-unknown-content-type
This is a server side issue, caused by whoever implemented it.
If you have access to the server code, you should change the Content-Type of the returned data.
If you do not have access, the best you can do is ask whoever does have access to fix this issue.

Unexpected missing fields in partial response to files list request

I modified the https://developers.google.com/drive/v2/reference/files/list example to get a list of all file items, using request partial resources.
def retrieve_all_files(service, fields = None):
"""Retrieve a list of File resources.
Args:
service: Drive API service instance.
fields: The fields (of each files Resource item!), e.g. 'id,title'
if not passed, get everything.
Returns:
List of File resources.
"""
result = []
page_token = None
while True:
try:
param = {}
if fields:
param['fields'] = 'nextPageToken,items(' + fields + ')'
if page_token:
param['pageToken'] = page_token
files = service.files().list(**param).execute()
result.extend(files['items'])
page_token = files.get('nextPageToken')
if not page_token:
break
except errors.HttpError, error:
print 'An error occurred: %s' % error
break
return result
In my test Drive folder I have a file that has a description string set. When I run
retrieve_all_files(drive_service)
without setting the fields parameter (so get everything), sure enough in the list of items, the file looks fine:
[{u'alternateLink': u'...',...
u'description': u'Description',
u'id': u'...',...},...]
but running
retrieve_all_files(drive_service, fields='id,description,title')
yields a list where none of the items have the 'description' property. Not all files have the 'description' property set; is this why the partial resource response is omitting the field even from items that have the property? I'm not sure if this is an undocumented feature that I didn't expect or a bug.
I was able to reproduce your issue. When using an authorized scopes list of:
https://www.googleapis.com/auth/drive
which should be full access, I was not able to get the description field returned. However, I found that if I also included the scope:
https://www.googleapis.com/auth/drive.appdata
the description field would return properly.
Can you confirm on your end that adding the above to your scopes resolves the issue? Seems like a bug on Google's end.
This was confirmed as a bug and a fix should be available in a few days.

Django dump JSON data

I'm trying to enter a word and have it show up on page through ajax. There something simple I'm missing...
So I'm sending the info like this with Jquery:
$.ajax({
url: url,
type:"POST",
data:{'word': word},
success: function(data){
//do something
}
});
and the information is getting into the view and saving into the DB. The problem happens when I try to return the new word:
def add_word(request, lecture_id):
l = get_object_or_404(Lecture, pk=lecture_id)
if request.method == "POST":
#see if there is a value with p
if request.POST.has_key('word') and request.POST['word'] != "":
success = {}
try:
oldWord = l.post_set.get(word=request.POST['word'])
except:
newWord = l.post_set.create(word=request.POST['word'], count = 1)
success = {'new': str(newWord.word), 'count': str(newWord.count)}
else:
oldWord.count += 1
oldWord.save()
success = {'old': str(oldWord.word), 'count': str(oldWord.count)}
return HttpResponse(json.dumps(success), mimetype="application/javascript")
return HttpResponse(reverse('post.views.lecture_display', args=(l.id,)))
Im getting a 500 error...
[13/Oct/2011 15:14:48] "POST /lecture/3/add HTTP/1.1" 500 66975
Without seeing the traceback, my guess is that what's failing is [one of]:
# A) This path is not resolving correctly (see named-URLs in Django's docs)
reverse('post.views.lecture_display', args=(l.id,))
# B) This word has unicode data, which can't simply be passed to ``str``
str(oldWord.word)
Open the URL directly in your browser, and you'll get the default Django traceback, 500 view.
I think you need to learn debugging rather that a particular fix.
Try opening that url without post data, see if there's a syntax or a name error.
If the problem persists, use ipdb or pudb package, insert the following line in the view and analyze what happens inside your code:
def myview(request, id):
import ipdb; ipdb.set_trace()
Use Chrome Developer Tools or Firebug to see what the server outputs and what urls it opens. Also take a look at Django Debug Toolbar and Werkzeug. The debug toolbar can show you all the templates that were rendered and all the local variables. Werkzeug also gives you a debug shell in any place of the call stack right from the browser.