如果您在Instagram上分享照片,则会在时间线上的照片上方看到以下消息。
" FB用户在Instagram上拍照。"
我的测试目前只显示:
" FB用户3秒前通过AppName"
我的图片邮政编码是:
$args = Array(
'url' => 'http://www.mySiteName.com/imageName.png',
'message' => 'Made on SiteName http://www.mySiteName.com',
);
$post_id = $this->facebook->api("/me/photos", "post", $args);
我认为我需要设置OpenGraph动作和对象,我已经完成了,但我不确定我是否正确设置了它们或如何测试它们。
我创建了一个动作" Make"和一个对象"集合"并尝试了以下内容:
$post_id = $this->facebook->api("/me/Namespace:make", "post", $args);
但得到错误:
"您尝试发布的操作无效,因为它未指定任何参考对象。必须至少指定以下属性之一:集合。"
Collection Get Code给出:
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# collection: http://ogp.me/ns/collection#">
<meta property="fb:app_id" content="appId" />
<meta property="og:type" content="collection" />
<meta property="og:url" content="Put your own URL to the object here" />
<meta property="og:title" content="Sample Collection" />
<meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" />
行动获取代码:
curl 'https://graph.facebook.com/me/nameSpace:make?access_token=TOKEN'
答案 0 :(得分:1)
我已经设法让它工作,并在下面张贴了生成的帖子,参考URL和Codeigniter代码的图像。
Make是我的OpenGraph Action和Collection是我的OpenGraph对象。
<强>参考:强>
http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/ http://developers.facebook.com/docs/opengraph/usergeneratedphotos/
$userId = $this->facebook->getUser();
// If user is not yet authenticated, the id will be zero
if($userId == 0){
// Generate a login url
$url = $this->facebook->getLoginUrl(array('scope'=>'email,user_photos,friends_photos,publish_stream'));
echo "<h2><a href='" . $url . "'>Login</a></h2>";
} else {
// Make Logout URL
$logoutUrl = $this->facebook->getLogoutUrl(array(
'next' => 'http://www.myUrl.com/logout/',
// URL to which to redirect the user after logging out
));
echo "<h2><a href='" . $logoutUrl . "'>Logout</a></h2>";
// Get User's data
$user = $this->facebook->api('/me');
echo "<p>Welcome <b>" . $user["name"] . '</b></p>';
echo("<p><b>User Details: </b>");
print_r($user);
echo("</p>");
// Get user's Permissions
$permissions = $this->facebook->api('/me/permissions');
echo("<p><b>User Permissions: </b>");
print_r($permissions);
echo("</p>");
if (isset($permissions['data'][0]['publish_stream'])) {
echo "<h3>Permission to Post</h3>";
} else {
$url = $this->facebook->getLoginUrl(array('scope'=>'email,user_photos,friends_photos,publish_stream'));
echo "<h3>NO Permission to Post: ";
echo "<a href='" . $url . "'>Get extra permissions</a></h3>";
}
// Upload an via OpenGraph Collection Object
$og_type = 'collection'; // Your Opengraph Object
$og_title = urlencode('This is my Title');
$og_description = urlencode('This is my Description');
$og_image = 'http://www.myUrl.com/big.png'; // At least 480px by 480px
$object_url = 'http://www.myUrl.com/fb_object_meta.php?fb:app_id=398917983475605&og:type='.$og_type.'&og:title='.$og_title.'&og:description='.$og_description.'&og:image='.urlencode($og_image);
// See this URL if you need the code for the dynamic meta data page
// http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/
$args = Array(
'collection' => $object_url,
'image[0][url]' => $og_image, // Possible to upload more than one user gen image e.g. image[1][url]
'image[0][user_generated]' => 'true',
//'message' => 'Made on myUrl http://www.myUrl.com', // This shows above the large pic
);
try {
$post_id = $this->facebook->api("/me/myUrl:make", "post", $args);
print_r($post_id);
}
catch (Exception $e)
{
print_r($e);
}
}
答案 1 :(得分:0)
在App控制台中添加OG操作的位置右侧会出现一个“获取代码”的链接。这将显示您需要包含的信息。
在您的情况下,您的args中应该有一个collection
参数,其中包含包含照片OG标记的网页的网址。
您可以通过单击在应用控制台中创建的collection
对象旁边的“获取代码”链接找到此标记。
<强>更新强>
通过将元标记添加到可访问网页的头部来打开图形。您需要将colleation
元数据添加到某个页面,然后添加到您正在进行的请求中的collection
参数中,添加页面的网址。