2017-08-15 106 views
0

我正在使用Swift 3和LinkedIn API向LinkedIn发布图像。ios swift post image to linkedin

该代码在我通过http URL发布图片时起作用。但是,当我使用URL,NSURL或包含本机iPhone上本地文件路径的字符串时,不会传输图像。

下面是表示正在传递数据的代码:

let parameters: Parameters = [ 
    "content": [ 
    "title": "Title", 
    "description": "Description", 
    "submitted-url": "https://www.google.com", 
    "submitted-image-url": --- This parameter is the problem -- 
    ], 
    "comment": "comment", 
    "visibility": [ 
    "code": "anyone" 
    ] 
] 

以下是我已经使用 “提交图像的URL” 的值:

  1. https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg

    • 这工作 - 引用网络上的网址
  2. “/private/var/mobile/Containers/Data/Application/9BFF81E8-DFE4-41EF-B25C-A82C79CF1708/tmp/yellopost.jpeg”

    • 以此为字符串的帖子中的所有数据到LinkedIn,除了像
  3. “文件:///private/var/mobile/Containers/Data/Application/9BFF81E8-DFE4-41EF-B25C-A82C79CF1708/tmp/yellopost.jpeg”

    • 失败
  4. “/private/var/mobile/Containers/Data/Application/9BFF81E8-DFE4-41EF-B25C-A82C79CF1708/tmp/yellopost.jpeg” 作为NSURL

    • 这种失败

那么,我该如何引用存储在iPhone上的图像呢?

在此先感谢。

回答

0

API只接受远程URL。否则后端将如何访问映像?

E.g:

{ 
    "comment": "Check out developer.linkedin.com!", 
    "content": { 
    "title": "LinkedIn Developers Resources", 
    "description": "Leverage LinkedIn's APIs to maximize engagement", 
    "submitted-url": "https://developer.linkedin.com", 
    "submitted-image-url": "https://example.com/logo.png" 
    }, 
    "visibility": { 
    "code": "anyone" 
    } 
} 
+0

感谢弥敦道。不幸的是,我创建的应用程序是一个可以在iPhone上运行的应用程序,不涉及远程服务器。图像来自用户手机上存储的内容或此刻拍摄的照片。所以,不涉及远程服务器。有没有办法伪装iPhone上的图像的本地路径作为远程URL? – Darrell