Android:将图片和文字发布到Instagram

Zak*_*Zak 3 android photo instagram

如何将图片和文字发布到Instagram?没问题,如果我必须打开Instagram应用程序,或者如果我通过api或其他.问题是我找不到如何:他们只有iphone挂钩,api是无法解决的.有人这样做了,还是知道了?谢谢.

小智 6

试试这个它对我有用.我会用它来分享我的产品细节.我将从服务器获取产品的详细信息,如名称,图像,描述,并在应用程序中显示,然后将其分享到Instagram.

从服务器获取图像URL.

URL url = ConvertToUrl(imgURL);
    Bitmap imagebitmap = null;
    try {
        imagebitmap = BitmapFactory.decodeStream(url.openConnection()
                .getInputStream());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

在instagram上发布图像和文本.

// post on instagram
            Intent shareIntent = new Intent(
                    android.content.Intent.ACTION_SEND);
            shareIntent.setType("image/*");
            shareIntent.putExtra(Intent.EXTRA_STREAM,
                    getImageUri(HomeActivity.this, result));
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, sharename);
            shareIntent.putExtra(
                    Intent.EXTRA_TEXT,
                    "Check this out, what do you think?"
                            + System.getProperty("line.separator")
                            + sharedescription);
            shareIntent.setPackage("com.instagram.android");
            startActivity(shareIntent);
Run Code Online (Sandbox Code Playgroud)

将Uri字符串转换为URL

private URL ConvertToUrl(String urlStr) {
try {
    URL url = new URL(urlStr);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(),
            url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    url = uri.toURL();
    return url;
} catch (Exception e) {
    e.printStackTrace();
}
return null;
Run Code Online (Sandbox Code Playgroud)

}

将位图转换为Uri

public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(
        inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
Run Code Online (Sandbox Code Playgroud)

}


sla*_*ton 5

我怀疑Instagram开发者是否会像Android一样为Android发布类似iPhone的钩子.

如果您想从应用程序共享图像,请使用以下意图:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Path/To/Image.jpg"));
startActivity(Intent.createChooser(i, "Share Image"));
Run Code Online (Sandbox Code Playgroud)

请注意,这将显示一个dialoge,允许用户选择要启动的照片共享应用程序.

  • 使用上述方法我不会在Instagram上上传图像... Plz帮助 (3认同)