2017-08-15 98 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