Android:将图像和文本发布到 Instagram

标签 android photo instagram

如何将图片和文字发布到 instagram? 如果我必须打开 instagram 应用程序,或者如果我通过 api 或其他方式打开,没问题。 问题是我找不到方法:他们只有 iphone Hook ,而且 api 是不可理解的。 有人这样做过,或者知道吗? 谢谢。

最佳答案

试试这个对我有用。我将用它来分享我的产品详细信息。我将从服务器获取产品的名称、图片、描述等详细信息并显示在应用程序中,然后将其分享到 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();
    }

在 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);

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

将 Bitmap 转换为 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);
}

关于Android:将图像和文本发布到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11563426/

相关文章:

android - 等待数据库完成插入数据,然后再继续下一个 Android Activity

swift - 使用 Swift 在图像上显示标记的用户名

ios - 如何创建比设备屏幕大的 UIImage?

安卓 Espresso : Testing error message is shown?

android - setOnClickListener崩溃

android - 如何在不调用 bringToFront() 的情况下将 View 置于最前面?

python - 在 Socket Python 上发送图片

php - 将照片发送到电子邮件机器人,将照片上传到网站

ios - 如何在 UIImagePickerController 中拍照后删除 "Preview" View ?

php - 将 Instagram API 订阅保存在数据库中