共享图像从自己的Android应用程序inastagram [英] share image to inastagram from own android application
问题描述
读音字试图从我的Android应用程序共享图像的Instagram应用程序.........我不能上传图片.........
i m trying to share the image from my android application to instagram application......... i cant upload the image.........
@SuppressWarnings("unchecked")
public Map<String, String> doUpload() {
Log.i(TAG, "Upload");
Long timeInMilliseconds = System.currentTimeMillis()/1000;
String timeInSeconds = timeInMilliseconds.toString();
MultipartEntity multipartEntity = new
MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
Map returnMap = new HashMap<String, String>();
// check for cookies
/* if( httpClient.getCookieStore() == null ) {
returnMap.put("result", "Not logged in");
return returnMap;
}*/
try {
// create multipart data
System.out.println("image path name : "+processedImageUri.getPath());
System.out.println("image file path : "+ImgFilePath);
File imageFile = new File(ImgFilePath);//processedImageUri.getPath());
FileBody partFile = new FileBody(imageFile);
StringBody partTime = new StringBody(timeInSeconds);
multipartEntity.addPart("photo", partFile );
multipartEntity.addPart("device_timestamp", partTime);
} catch ( Exception e ) {
Log.e(TAG,"Error creating mulitpart form: " + e.toString());
returnMap.put("result", "Error creating mulitpart form: " + e.toString());
return returnMap;
}
// upload
try {
System.out.println("111111111111111111");
System.out.println("multipart entity value : "+multipartEntity.toString());
HttpPost httpPost = new HttpPost(Utils.UPLOAD_URL);
httpPost.setEntity(multipartEntity);
System.out.println("http post vlaue : "+httpPost.toString());
System.out.println("http client value : "+httpClient.toString());
HttpResponse httpResponse = httpClient.execute(httpPost);
System.out.println("Http response value : "+httpResponse.toString());
HttpEntity httpEntity = httpResponse.getEntity();
Log.i(TAG, "Upload status: " + httpResponse.getStatusLine());
System.out.println("staus entity value : "+httpResponse.getStatusLine().toString());
System.out.println("http status : "+HttpStatus.SC_OK);
// test result code
if( httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK ) {
Log.e(TAG, "Login HTTP status fail: " + httpResponse.getStatusLine().getStatusCode());
returnMap.put("result", "HTTP status error: " + httpResponse.getStatusLine().getStatusCode() );
return returnMap;
}
// test json response
// should look like
/*
{"status": "ok"}
*/
if( httpEntity != null ) {
BufferedReader reader = new BufferedReader(new InputStreamReader(httpEntity.getContent(), "UTF-8"));
String json = reader.readLine();
System.out.println("Entity value : "+json);
JSONTokener jsonTokener = new JSONTokener(json);
JSONObject jsonObject = new JSONObject(jsonTokener);
Log.i(TAG,"JSON: " + jsonObject.toString());
String loginStatus = jsonObject.getString("status");
if( !loginStatus.equals("ok") ) {
Log.e(TAG, "JSON status not ok: " + jsonObject.getString("status"));
returnMap.put("result", "JSON status not ok: " + jsonObject.getString("status") );
return returnMap;
}
}
} catch( Exception e ) {
Log.e(TAG, "HttpPost exception: " + e.toString());
returnMap.put("result", "HttpPost exception: " + e.toString());
return returnMap;
}
// configure / comment
try {
HttpPost httpPost = new HttpPost(Utils.CONFIGURE_URL);
String partComment = txtCaption.getText().toString();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("device_timestamp", timeInSeconds));
postParams.add(new BasicNameValuePair("caption", partComment));
httpPost.setEntity(new UrlEncodedFormEntity(postParams, HTTP.UTF_8));
System.out.println("http client value : "+httpClient.toString());
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
// test result code
if( httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK ) {
Log.e(TAG, "Upload comment fail: " + httpResponse.getStatusLine().getStatusCode());
returnMap.put("result", "Upload comment fail: " + httpResponse.getStatusLine().getStatusCode() );
return returnMap;
}
returnMap.put("result", "ok");
return returnMap;
} catch( Exception e ) {
Log.e(TAG, "HttpPost comment error: " + e.toString());
returnMap.put("result", "HttpPost comment error: " + e.toString());
return returnMap;
}
以上是code。使用上载的形象和这个网址这是即时通讯= UPLOAD_URLhttp://instagr.am/api/v1/media/upload/...... .......
请谁能帮我上传的图片到Instagram的.......提前感谢
the above is the code which i m using for upload the image and the url for this is UPLOAD_URL = "http://instagr.am/api/v1/media/upload/" ............. pls can anyone help me to upload the image to instagram....... Thanks in advance
推荐答案
在Instagram的API不支持尚未上传
The Instagram API doesn't support uploading yet.
从Instagram的API文档:
From the Instagram API Docs:
<强>此时,通过API上传是不可能的。我们有意识地选择不添加此原因如下:
Instagram的是关于在旅途中你的生活 - 我们希望鼓励照片
从应用程序内。然而,在未来我们可以给白名单
按个别访问个人应用上的情形。我们想打架
垃圾邮件和放大器;低质量的照片。一旦我们允许从其他来源上传,
这是更难控制随之而来到Instagram的生态系统。所有
这是说,我们正在努力工作,以确保用户有一个
我们的平台上一致的高品质体验。
Instagram is about your life on the go – we hope to encourage photos from within the app. However, in the future we may give whitelist access to individual apps on a case by case basis. We want to fight spam & low quality photos. Once we allow uploading from other sources, it's harder to control what comes into the Instagram ecosystem. All this being said, we're working on ways to ensure users have a consistent and high-quality experience on our platform.
这篇关于共享图像从自己的Android应用程序inastagram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!