3

i try to push a timeline card to the Glass from my android application. i use this code:

String BASE_URL = "https://www.googleapis.com/upload/mirror/v1/";

    try {
        final HttpPost request = new HttpPost();
        request.setURI(new URI(BASE_URL + "timeline"));
        request.addHeader("Authorization", String.format("Bearer %s", token));
        request.addHeader("Content-Type", "application/json");
        request.setEntity(new StringEntity(json.toString()));

        // Execute the request on a background thread
        mThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    final HttpResponse response = mClient.execute(request);
                    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                callback.onSuccess(response);
                            }
                        });
                    } else {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                callback.onFailure(response, null);
                            }
                        });
                    }
                } catch (final IOException e) {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            callback.onFailure(null, e);
                        }
                    });
                }
            }
        });
    } catch (UnsupportedEncodingException e) {
        // Note: This should never happen
    } catch (URISyntaxException e) {
        // Note: This should never happen
    }

the json is like this :

{"notification":{"level":"DEFAULT"},"text":"Pizza and spaghetti"}

but the service respond with an error :

"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Media type 'application/json' is not supported. Valid media types: [image/*, audio/*, video/*]"
}
],
"code": 400,
"message": "Media type 'application/json' is not supported. Valid media types: [image/*, audio/*, video/*]"
}
}

i follow the code from here: https://github.com/twaddington/mirror-quickstart-android

any idea?

Ps. there is another way to push a timeline card from an android application to the google glass?

Thanks

ilmetu
  • 448
  • 11
  • 27
  • can you give me the full url with parameters?and this url is get or post?when i try to run this url response not display. – ishu Dec 20 '13 at 13:40
  • i update the question with the complete url : https://www.googleapis.com/upload/mirror/v1/timeline , is a POST request, there isn't a parameter, only header and entity. let me know if you need something else! thanks for your help – ilmetu Dec 20 '13 at 13:48
  • when i run thi url in browser it show method not allowed – ishu Dec 20 '13 at 13:57
  • you need a correct token , look at Authorization parameter, you cannot do it from a browser, it work only within an app, and with the correct oauth2.0 token – ilmetu Dec 20 '13 at 14:02

1 Answers1

2

As you can see in the Google Docs (https://developers.google.com/glass/v1/reference/timeline/insert) this request only accept mutimedia data as 'Content-type'.

Try changing this line with the correct content type (image/, audio/, video/*) : request.addHeader("Content-Type", "application/json");

You will have to add the multimedia object inside your HTTPost object. More info about that: Sending images using Http Post

--EDIT-- The request you want to do (only metadata, without multimedia) has to be done to: https://www.googleapis.com/mirror/v1/ (notice that there is not the upload word).

Community
  • 1
  • 1
pozuelog
  • 1,284
  • 13
  • 27
  • but i want to send only text not image audio or videos ... i follow this https://developers.google.com/glass/develop/mirror/timeline give it a look please, maybe i'm wrong... – ilmetu Dec 20 '13 at 13:55
  • OH MY GOD! DAMN COPY PASTE! Thank you so much! – ilmetu Dec 20 '13 at 14:16