2013-01-03 35 views
0

我有模塊上的Joomla 1.5,該模塊內容的畫面,它有這樣的鏈接文章:分享文章到Facebook的從的Joomla模塊

<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

我想你使用Facebook的圖形API的

請參考下文提到的鏈接,更好understang http://developers.facebook.com/docs/reference/php/facebook-api/

從這個鏈接下載PHP SDK https://github.com/facebook/php-sdk

然後有一個文件夾名稱「示例」由2個文件組成 1.)example.php 2.)with_js_sdk.php

在這兩個文件代碼中,頂部的代碼如下 //創建我們的應用程序實例(將其替換爲您的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>'; 

    } 

?> 
+0

我嘗試這一步但對我的網站不利 –

0

您的網站連接至Facebook後,您可以在此onclick事件的圖片鏈接=>

onclick="FB.ui({method: 'stream.share', display:'button', u: 'http://www.cc.com/index.php?id-22' }, null);" 
相關問題