コマンドラインで OGP をデバッグする


Facebook のデバッガー ( http://developers.facebook.com/tools/debug ) も便利ですが、Graph API 経由でも ogp を確認出来ます。

#!/usr/bin/env php
<?php

if (!isset($argv[1])) {
    echo "Usage: php ogp.php [URL]", PHP_EOL;
    exit;
}

$data = http_build_query(array(
    'id'     => $argv[1],
    'scrape' => 'true',
));

$context = array(
    'http' => array(
        'method' => 'POST',
        'header' => implode("\r\n", array(
            'Content-Type: application/x-www-form-urlencoded',
            'Content-Length: '.strlen($data),
        )),
        'content' => $data,
    ),
);

var_dump(json_decode(file_get_contents(
    'https://graph.facebook.com',
    false,
    stream_context_create($context)
), true));

うん、雑なコード。