【问题标题】:URL Scheme to post to Instagram Stories发布到 Instagram 故事的 URL 方案
【发布时间】:2017-05-31 11:05:21
【问题描述】:

有没有办法将视频或照片直接发布到用户 Instagram 帐户的 Instagram 快拍?对于 Instagram 上的普通照片分享,您可以使用 URL Scheme 并直接打开编辑器。故事也有办法吗?

谢谢!

【问题讨论】:

标签: ios objective-c instagram instagram-api url-scheme


【解决方案1】:

Swift 4.2 版本的knshn's answer

func shareBackgroundImage() {
    let image = UIImage(imageLiteralResourceName: "backgroundImage")

    if let pngImage = image.pngData() {
        backgroundImage(pngImage, attributionURL: "http://your-deep-link-url")
    }
}

func backgroundImage(_ backgroundImage: Data, attributionURL: String) {
    // Verify app can open custom URL scheme, open if able

    guard let urlScheme = URL(string: "instagram-stories://share"),
        UIApplication.shared.canOpenURL(urlScheme) else {
            // Handle older app versions or app not installed case

            return
    }

    let pasteboardItems = [["com.instagram.sharedSticker.backgroundImage": backgroundImage,
                            "com.instagram.sharedSticker.contentURL": attributionURL]]
    let pasteboardOptions: [UIPasteboard.OptionsKey: Any] = [.expirationDate: Date().addingTimeInterval(60 * 5)]

    // This call is iOS 10+, can use 'setItems' depending on what versions you support
    UIPasteboard.general.setItems(pasteboardItems, options: pasteboardOptions)

    UIApplication.shared.open(urlScheme)
}

【讨论】:

  • 有人可以详细说明 attributionURL: "your-deep-link-url" 会是什么样子吗?我正在尝试让应用程序 App Store 页面链接出现在左上角的 Facebook Story 用户名下。
  • @Krekin 这是一个正式的“封闭测试版”功能,似乎已从文档中删除。
  • 根据developers.facebook.com/docs/instagram/sharing-to-stories 此处的文档,新的归属方式似乎是使用此 url-scheme:“instagram-stories://share?source_application=com.my.app”跨度>
【解决方案2】:

Instagram 自 2018 年 3 月起正式支持此功能。https://developers.facebook.com/docs/instagram/sharing-to-stories/

对于 iOS:

您需要将instagram-stories 添加到您应用的Info.plist 中的LSApplicationQueriesSchemes 键中。

此示例代码展示了如何向 Instagram 应用传递背景层图像资产和归因深层链接。

- (void)shareBackgroundImage {
      [self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"])
             attributionURL:@"http://your-deep-link-url"];
}

- (void)backgroundImage:(NSData *)backgroundImage 
         attributionURL:(NSString *)attributionURL {

  // Verify app can open custom URL scheme, open if able
  NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"];
  if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) {

        // Assign background image asset and attribution link URL to pasteboard
        NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : backgroundImage,
                                       @"com.instagram.sharedSticker.contentURL" : attributionURL}];
        NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
        // This call is iOS 10+, can use 'setItems' depending on what versions you support
        [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];

        [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
  } else {
      // Handle older app versions or app not installed case
  }
}

【讨论】:

  • 这是一个边界线link-only answer。您应该在此处扩展您的答案以包含尽可能多的信息,并使用该链接仅供参考。
  • 嗨,当 Instagram 应用未安装在设备上时,有没有办法让应用在 Instagram 上共享数据?
【解决方案3】:

您可以使用this answer 将PHAsset 的标识符转换为资产URL,然后使用this logic 将其格式化为instagram:// URL。过去只能发布传统的 Instagram 帖子,但在过去几周内,它实际上会提示用户是否想使用您在发布时提供的资产制作故事或帖子!

【讨论】:

    【解决方案4】:

    如果你下载 instagram 的 .ipa 并查看他们的 Info.plist,我们可以找到:

        <key>CFBundleURLSchemes</key>
        <array>
          <string>instagram-stories</string>
          <string>fb124024574287414</string>
          <string>instagram</string>
          <string>instagram-capture</string>
          <string>fsq+kylm3gjcbtswk4rambrt4uyzq1dqcoc0n2hyjgcvbcbe54rj+post</string>
        </array>
    

    但它当然是私人的(非官方的)并且没有被 Instagram 记录。如果有人现在如何使用它/查找参数,我真的很想知道!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      相关资源
      最近更新 更多