Re: Android integration

51 views
Skip to first unread message
Message has been deleted

Chuck Garofalo

unread,
Mar 4, 2013, 9:55:42 AM3/4/13
to spring...@googlegroups.com
Hi.  I looked in the logs for this error message but strangely I did not see it.  Could you give it another try and reply with the date/time (and timezone) and I can take another look?

Thanks,
Chuck

On Thursday, February 28, 2013 10:41:55 AM UTC-5, tofi9 wrote:
I've trying to connect to your API via our Android app. OAuth and REST works. However, I'm having issues with posting a new image block into a workbook.

My request is:

POST http://springpad.com/api/users/me/blocks/2d35d337-22cc-429c-b910-86f34be00a83/photos?filename=testme.jpg&description=bla&encoding=base64

Content-Type: image/jpeg
Content-Length: 12345 (complete size of string, including pre-fix "data:image/jpeg;base64,")

data:image/jpeg;base64,<BASE64DATA>

The error I'm getting is:

Error attaching a photo. This doesn't necessarily mean that there's a problem. The phone will resend it.

I've tried to change the value of Content-Type into "image/jpeg", and produced the same error.

My oAuth customer key is: fd341b6afa414ae19ebe8bab2822ae01

Any sample code is appreciated. I use the oAuth Scribe Library for Java. Below you'll find my test code.



OAuthService service = new ServiceBuilder()

.provider(SpringpadApi.class)

.apiKey("fd341b6afa414ae19ebe8bab2822ae01")

.apiSecret("XXXXX")

//.debug()

.debugStream(System.out)

.build();


Token accessToken = new Token("ed368e29841e33706479ebb6cd221823",

"XXX");


try {

File file = new File("/Users/taoufik/Desktop/logo.jpg");

byte [] fileData = new byte[(int)file.length()];

DataInputStream dis = new DataInputStream((new FileInputStream(file)));

dis.readFully(fileData);

dis.close();


OAuthRequest request = new OAuthRequest(

Verb.POST,

"http://springpad.com/api/users/me/blocks/2d35d337-22cc-429c-b910-86f34be00a83/photos?filename=testme.jpg&description=bla&encoding=base64");

request.addHeader("Content-Type", "image/jpeg");

String data = "data:image/jpeg;base64," + new Base64().encodeToString(fileData);

request.addPayload(data);

service.signRequest(accessToken, request);

Response response = request.send(); 

String content = response.getBody();

System.out.println(content);

} catch (IOException e) {

e.printStackTrace();

}



Chuck Garofalo

unread,
Mar 4, 2013, 12:39:01 PM3/4/13
to spring...@googlegroups.com
Hi Taoufik.  I strangely don't see in the logs what I'm expecting.  There is a bit of noise there so the username that you are using would help.  Can you provide that to me?

Thanks,
Chuck

On Monday, March 4, 2013 11:21:34 AM UTC-5, tofi9 wrote:
hi Chuck,

Thanks for the reply.

I've just tried again now: Mon, 04 Mar 2013 16:14 UTC+0 (London, UK). 

I've also enabled wireshark, this is the data over the wire. I've replaced all the privacy sensitive info with XXXXXXX (7 times X):

POST /api/users/me/blocks/2d35d337-22cc-429c-b910-86f34be00a83/photos?encoding=base64 HTTP/1.1
Authorization: OAuth oauth_signature="XXXXXXX", oauth_version="1.0", oauth_nonce="1509043094", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="XXXXXXX", oauth_token="XXXXXXX", oauth_timestamp="1362413680"
X-Spring-Client: XXXXXXX
Accept: application/javascript
Content-Type: application/octet-stream
User-Agent: Java/1.6.0_41
Connection: close
Content-Length: 22195

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QaWRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAALAAAAcgEyAAIAAAAUAAAAfodpAAQAAAABAAAAkgAAANQAAABIAAAAAQAAAEgAAAABR0lNUCAyLjguMAAAMjAxMjoxMDoxMiAyMzowN....... (omitted the rest)

Date: Mon, 04 Mar 2013 16:14:42 GMT
Server: Apache-Coyote/1.1
Expires: Sun, 03 Mar 2013 16:14:42 GMT
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: application/javascript;charset=UTF-8
Content-Language: en-US
Content-Length: 138
Via: 1.1 springpad.com
X-Robots-Tag: noindex, nofollow, noarchive
Vary: Accept-Encoding
Via: 1.1 springpad.com
Connection: close

{
"status":"error",
"message":"Error attaching a photo. This doesn't necessarily mean that there's a problem. The phone will resend it."
}


Thanks for your help!

Taoufik

Pete Aykroyd

unread,
Mar 4, 2013, 1:56:09 PM3/4/13
to spring...@googlegroups.com
There was some weirdness in using this API that I remember debugging for someone else on the list sometime ago. 


One thing to try is using a png instead. Change the file to a png, use that on the filename query param, and also in the beginning section of your post data. Let me know if that doesn't work. If that does, then we'll try something with the jpg. 

Cheers,

Pete


--
You received this message because you are subscribed to the Google Groups "Springpad Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to springpaddev...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Chuck Garofalo

unread,
Mar 11, 2013, 8:28:15 AM3/11/13
to spring...@googlegroups.com
Hi Taufik,

Ok, one of the issues is that the item you are uploading a photo to must first exist.  So you can use the command api to create a photo spring.  Then you can attach a photo to this spring using the photo api using the uuid of the photo spring, not the notebook you are putting the spring in.

Please give this a try and let us know if you have any questions.

Regards,
Reply all
Reply to author
Forward
0 new messages