【问题标题】:Share in Instagram and get callback在 Instagram 分享并获得回电
【发布时间】:2015-09-14 07:01:03
【问题描述】:

我必须将我的应用程序中的图像分享到 instagram。我浏览了 Instagram 开发者文档,他们只提到了通过 Intent 方法进行分享,但我需要的是在成功发布后我必须得到回调。

private void createInstagramIntent(String type, String mediaPath){

    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);

    // Add the URI to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);

    // Broadcast the Intent.
    startActivity(Intent.createChooser(share, "Share to"));
}

有什么办法吗?

【问题讨论】:

  • @rekire 当然会得到一个回调到 startActivityForResult。但我们无法确定用户是否共享。如果你按下后退按钮,也会调用 startActivityForResult
  • 他们的 API 很安静:instagram.com/developer/mobile-sharing/android-intents 没有提供更多信息。
  • 如果我的手机上没有安装 Instagram 怎么办?
  • @rekire 即使没有安装 Instagram,还有其他方法可以在 Android 应用中分享吗?

标签: android callback instagram sharing instagram-api


【解决方案1】:

有几个选项取决于它们的 API。首先参考他们的Android Intents,恕我直言,这是一个不好的例子,这或多或少是Android中如何共享数据的默认方式。你想要的更像是只打开他们的应用程序。对于这种情况,是否有 setPackage() 选项:

// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);

// Limit this call to instagram
share.setPackage("com.instagram.android");

// Set the MIME type
share.setType(type);

// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);

// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);

try {
    // Fire the Intent.
    startActivityForResult(share, REQUEST_CODE);
} catch(ActivityNotFoundException e) {
    // instagram not installed
}

现在对于未安装 instagram 的情况,您几乎迷路了。如果没有其他 SDK,则无能为力。

一个非常复杂的解决方法可能是将文件上传到您自己的后端。然后打开浏览器以访问 oauth 令牌以通​​过您的后端上传图像。然而,这是一个我会避免的安静昂贵的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    相关资源
    最近更新 更多