Hi all,
I used oauth-signpost http://code.google.com/p/oauth-signpost/ to get
"AccessToken" & "TokenSecret".
My problem is I can use "AccessToken" & "TokenSecret" to get my picasa
album list(using oauth-signpost ), but I don't know how to append
these token to http post to upload photo.
//get album list
if (AccessToken!=null && TokenSecret!=null) {
OAuthConsumer mOAC = new DefaultOAuthConsumer("anonymous",
"anonymous",SignatureMethod.HMAC_SHA1);
mOAC.setTokenWithSecret(AccessToken, TokenSecret);
mOAC.sign(request)
Log.v(TAG, "Sending request...");
request.connect();
mInputStream = request.getInputStream();
ps. My "AccessToken" and "TokenSecret" look like "1/tC7-
TDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNfNevWA", "KgfxTxxxxxxxxxxxxxxxx+Cr"
//upload photo to picasa
URL url = new URL(https://picasaweb.google.com/data/feed/api/
user/default/albumid/default);
postConnection = (HttpURLConnection) url.openConnection();
File imgFile = new File("/sdcard/test/test.jpg");
long imgLength = imgFile.length();
postConnection.setRequestMethod("POST");
postConnection.setDoInput(true);
postConnection.setDoOutput(true);
postConnection.setUseCaches (false);
PrintWriter writer = null;
try {
OutputStream output = postConnection.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(output,
"UTF-8"), true); // true = autoFlush, important!
// Send binary file.
writer.println("Content-Type: image/jpeg");
writer.println("Content-Length: "+imgLength);
writer.println("Slug: plz-to-love-realandroid.jpg");
writer.println();
InputStream input = null;
try {
input = new FileInputStream(imgFile);
byte[] buffer = new byte[1024];
for (int length = 0; (length = input.read(buffer)) > 0;)
{
output.write(buffer, 0, length);
}
output.flush(); // Important! Output cannot be closed.
Close of writer will close output as well.
} finally {
if (input != null)
try {
input.close();
} catch (IOException logOrIgnore) {}
}
} finally {
if (writer != null) writer.close();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v(TAG, "Sending postConnection...");
postConnection.connect();
Log.v(TAG, "postConnection Response: " +
postConnection.getResponseCode() + " "
+ postConnection.getResponseMessage());
---------------------------------------------------------------------------------------------------------------
After execute post photo, I got "postConnection Response: 415
Unsupported Media Type"
Thank You!!!
JuSofie
--
You received this message because you are subscribed to the Google Groups
"Google Picasa Web Albums API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-picasa-data-api?hl=en.