【问题标题】:share image to inastagram from own android application从自己的 android 应用程序将图像共享到 instagram
【发布时间】:2012-09-21 13:13:14
【问题描述】:

我正在尝试将图像从我的 android 应用程序共享到 instagram 应用程序............我无法上传图像............

@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;
    }

上面是我用来上传图片的代码,这个网址是 UPLOAD_URL = "http://instagr.am/api/v1/media/upload/" ...... …… 请问谁能帮我把图片上传到instagram.......提前谢谢

【问题讨论】:

    标签: android instagram


    【解决方案1】:

    Instagram API 尚不支持上传。

    来自 Instagram API 文档:

    目前无法通过 API 上传。我们有意识地选择不添加它,原因如下:

    Instagram 是关于你在旅途中的生活——我们希望鼓励照片 从应用程序内。但是,将来我们可能会给出白名单 根据具体情况访问各个应用程序。我们想战斗 垃圾邮件和低质量的照片。一旦我们允许从其他来源上传, 很难控制进入 Instagram 生态系统的内容。全部 话虽如此,我们正在努力确保用户拥有 在我们的平台上提供一致且高质量的体验。

    【讨论】:

    • 谢谢。有没有其他可能的方法可以将我的图片分享到 Instagram 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    相关资源
    最近更新 更多