10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift で OGP 情報の取得

Posted at

目的

Swift で任意のWebページのOGP情報を取得する

方法

任意のパッケージマネージャで https://github.com/satoshi-takano/OpenGraph をインストールする。
OpenGraph を利用するファイルの冒頭で import して

import OpenGraph

fetch メソッドに任意の URL を渡す

OpenGraph.fetch(url) { og, error in
    print(og?[.title]) // => og:title of the web site
    print(og?[.type])  // => og:type of the web site
    print(og?[.image]) // => og:image of the web site
    print(og?[.url])   // => og:url of the web site
}

コールバックで OGP 情報が受け取れる。


以上

※半分自分のライブラリの宣伝でした

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?