This is OpenGraph parser for Java.
Maven Central : ogparser4j
maven
<dependency >
<groupId >com.github.siyoon210</groupId >
<artifactId >ogparser4j</artifactId >
<version >1.0.1</version >
</dependency >
gradle
implementation ' com.github.siyoon210:ogparser4j:1.0.1'
How to Get OpenGraph object from your target url.
OgParser ogParser = new OgParser ();
OpenGraph openGraph = ogParser .getOpenGraphOf ("https://target.url" );
How to Get OpenGraph Value
< meta property ="og:title " content ="Open Graph protocol " />
OpenGraph .Content title = openGraph .getContentOf ("title" );
String titleValue = title .getValue (); // "Open Graph protocol"
How to Get Extra Data
< meta property ="og:image " content ="https://ogp.me/logo.png " />
< meta property ="og:image:type " content ="image/png " />
OpenGraph .Content image = openGraph .getContentOf ("image" );
String imageType = image .getExtraDataValueOf ("type" ); // "image/png"
< meta property ="og:image " content ="https://ogp.me/logo.png " />
< meta property ="og:image " content ="https://ogp.me/logo2.png " />
OpenGraph .Content imageIndex0 = openGraph .getContentOf ("image" , 0 ); // you can omit index 0.
OpenGraph .Content imageIndex1 = openGraph .getContentOf ("image" , 1 );
String image0 = imageIndex0 .getValue (); // "https://ogp.me/logo.png"
String image1 = imageIndex1 .getValue (); // "https://ogp.me/logo2.png"
< meta property ="og:image " content ="https://ogp.me/logo.png " />
< meta property ="og:image:width " content ="300 " />
< meta property ="og:image " content ="https://ogp.me/logo2.png " />
< meta property ="og:image:width " content ="200 " />
OpenGraph .Content imageIndex0 = openGraph .getContentOf ("image" , 0 ); // you can omit index 0.
OpenGraph .Content imageIndex1 = openGraph .getContentOf ("image" , 1 );
String image0Width = imageIndex0 .getExtraDataValueOf ("width" ); // "300"
String image1Wdith = imageIndex1 .getExtraDataValueOf ("width); // " 200 "
OpenGraph Protocol Summary
OpenGraph Protocol Summary