我已经通过在die('test')
函数的第一行放置onContentAfterSave()
语句来检查此触发器是否正常工作。我想知道为什么里面的其余代码不起作用。
defined('_JEXEC') or die ('Access Deny');
class plgContentMypost extends JPlugin {
public function onContentAfterSave( $context, $article, $isNew )
{
require_once JPATH_ROOT . '/plugins/content/mypost/src/facebook.php';
$appId = '233015226851759';
$secret = '95daba36aa48679229e';
$returnurl = 'http://localhost/sample/examples';
$permissions = 'manage_pages, publish_stream, publish_actions';
// Create our Application instance (replace this with your appId and secret).
$fb = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
));
$access_token = $fb->getAccessToken();
$name = 'LUPIN';
$message = 'this is a message';
$description = 'this is my description';
$pictureUrl = 'http://rofi.philfire.com.ph/joomla16/images/iphone-4-top-new-1.jpg';
$link = 'http://rofi.philfire.com.ph/joomla16/';
$attachment = array(
'access_token' => $access_token,
'message' => "$message",
'name' => "$name",
'description' => "$description",
'link' => "$link",
'picture' => "$pictureUrl",
// 'actions' => array('name'=>'Try it now', 'link' => "$appUrl")
);
$post_id = $fb->api("me/feed","POST",$attachment);
}
}
如果我将此代码作为独立代码使用,它可以正常工作并在Facebook上发布内容。
require_once '/src/facebook.php';
$appId = '233015226851759';
$secret = '95daba36aa48679229e';
$returnurl = 'http://localhost/sample/examples';
$permissions = 'manage_pages, publish_stream, publish_actions';
// Create our Application instance (replace this with your appId and secret).
$fb = new Facebook(array(
'appId' => $appId,
'secret' => $secret,
));
$access_token = $fb->getAccessToken();
$name = 'LUPIN';
$message = 'this is a message';
$description = 'this is my description';
$pictureUrl = 'http://rofi.philfire.com.ph/joomla16/images/iphone-4-top-new-1.jpg';
$link = 'http://rofi.philfire.com.ph/joomla16/';
$attachment = array(
'access_token' => $access_token,
'message' => "$message",
'name' => "$name",
'description' => "$description",
'link' => "$link",
'picture' => "$pictureUrl",
// 'actions' => array('name'=>'Try it now', 'link' => "$appUrl")
);
$post_id = $fb->api("me/feed","POST",$attachment);
下面是我的XML文件:
<?xml version="1.0" ?>
<extension type="plugin" version="2.5.0" method="upgrade" group="content">
<name>My Post</name>
<author>Mark Orosa</author>
<version>1.0.0</version>
<description>This is My FB Post Plugin</description>
<files>
<filename plugin="mypost">mypost.php</filename>
<folder>src</folder>
<filename>mypost.xml</filename>
<filename>index.html</filename>
</files>
<config></config>
</extension>
答案 0 :(得分:2)
您在require_once上使用的文件路径不正确。 src目录位于/ path_to_your_install / plugins / content / mypost
下所以你最好尝试这样的事情:
require_once JPATH_ROOT . '/plugins/content/mypost/src/facebook.php'
检查在此http://docs.joomla.org/Constants
使用正确的JPATH常量也许这http://docs.joomla.org/J2.5:Creating_a_Plugin_for_Joomla也可以帮到你。
问候!