我在joomla 1.5上有模块,这个模块的内容图片和它有这样的文章的链接:
<a href="www.cc.com/index.php?id-22"><img src="....></a>
所以我需要当用户点击此图片时在<a href="www.cc.com/index.php?id-22"><img src="....></a>
上分享文章到Facebook。
答案 0 :(得分:0)
我希望您使用Facebook Graph API
请参阅下面提到的链接以获得更好的信息 http://developers.facebook.com/docs/reference/php/facebook-api/
从此链接下载PHP SDK https://github.com/facebook/php-sdk
然后有一个文件夹名称“examples”,由2个文件组成 1.)example.php 2.)with_js_sdk.php
在顶部的文件代码中都有这样的代码 //创建我们的Application实例(用你的appId和secret替换它)。
$facebook = new Facebook(array(
'appId' => '103562503147391',
'secret' => 'c753579eb3e805d0155fc5542c54260d',
));
您需要从此处https://developers.facebook.com/apps创建自己的APP,并获得 appId 和秘密。
下面提到的代码会在你的facebook墙上发布链接
<?php
/**
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if($user) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
// Give the user a logout link
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {
// No user, so print a link for the user to login
// To post to a user's wall, we need publish_stream permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
答案 1 :(得分:0)
将您的网站连接到Facebook后,您可以将此事件点击到您的图片链接=&gt;
onclick="FB.ui({method: 'stream.share', display:'button', u: 'http://www.cc.com/index.php?id-22' }, null);"