Php 在facebook登录后重定向到同一页面,以便我可以相应地发布帖子
可能重复:Php 在facebook登录后重定向到同一页面,以便我可以相应地发布帖子,php,facebook,magento,facebook-graph-api,Php,Facebook,Magento,Facebook Graph Api,可能重复: 下面是我的代码,我一直在尝试制作一个脚本,如果我在facebook上发布的复选框被选中,那么首先会检查用户是否登录facebook,但如果他没有登录,那么他将被重定向到facebook页面,登录到该页面并重定向回同一页面。 我正在使用magento,当我检查checbox以在facebook上发布时,它会将我成功重定向到facebook并在那里登录我,但它不会将我成功重定向回,并给出无效表单数据的错误 请告诉我如何修改以下代码,以帮助我完成我一直试图完成的任务 function
下面是我的代码,我一直在尝试制作一个脚本,如果我在facebook上发布的复选框被选中,那么首先会检查用户是否登录facebook,但如果他没有登录,那么他将被重定向到facebook页面,登录到该页面并重定向回同一页面。 我正在使用magento,当我检查checbox以在facebook上发布时,它会将我成功重定向到facebook并在那里登录我,但它不会将我成功重定向回,并给出无效表单数据的错误 请告诉我如何修改以下代码,以帮助我完成我一直试图完成的任务
function myfunction()
{
$myformData = $this->getRequest()->getPost('myform');
$fbpost=$myformData['fbpost'];
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'fileUpload' => true,
)); //making object for facebook connectivity
$user = $facebook->getUser();
if($user==0 && isset($fbpost)) // checking if user is login to facebook or not
{
header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,publish_stream,user_photos,manage_pages'))}"); //redirecting to facebook
}
else
{
// $con = $this->_getConnection();
// Mage::helper('Octopus/')
$store = Mage::app()->getStore();$userId = $store->getName();
$db = Mage::getSingleton('core/resource')->getConnection(core_write);
$myformData = $this->getRequest()->getPost('myform');
$fbpost=$myformData['fbpost'];
if(isset($fbpost))
{
echo Mage::helper('function')->test();
}
$couponId = $myformData['coupon_id'];
$coupontype=$myformData['coupon_type'];
$select = $db -> select();
$select -> from('ops_mobile_coupons')
-> where('id =?',$couponId);
$data = $db -> fetchRow($select);
$select = $db -> select() -> from('ops_image_type_coupon_details')->where('coupon_id = ?',$data['id']);
$x = $db->fetchRow($select);
$image=$x['image_path'];
// -> andWhere('client_id = ?', $userId);
if(isset($fbpost) and $coupontype == 'image')
{
//Image Facebook Starts
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'fileUpload' => true,
));
$accounts_list = $facebook->api('/me/accounts');
$accounts_list = $facebook->api('/me/accounts');
//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
if($account['id'] == 'me'){ // my page id =123456789
$access_token = $account['access_token'];
//echo "<p>Page Access Token: $access_token</p>";
}
}
$attachment = array('message' => 'image coupon',
'access_token' => $access_token,
'link' => 'http://operture.com/jeegesh/index.php/octopus/adminhtml_coupon/postpart2/key/34f1bf523a35bc8c9213d669097f8e50/',
'source' => $image,
);
$status = $facebook->api('/me/feed', 'POST', $attachment); // my page id =123456789
//var_dump($status);
}
//Image Facebook Ends }}
函数myfunction()
{
$myformData=$this->getRequest()->getPost('myform');
$fbpost=$myformData['fbpost'];
$app\u id=“app\u id”;
$app\u secret=“app\u secret”;
$facebook=新的facebook(数组)(
“appId”=>$app\u id,
'secret'=>$app\u secret,
“cookie”=>正确,
“fileUpload”=>true,
));//为facebook连接创建对象
$user=$facebook->getUser();
if($user==0&&isset($fbpost))//检查用户是否登录到facebook
{
标题(“位置:{$facebook->getLoginUrl(数组('scope'=>'photo\u upload,publish\u stream,user\u photos,manage\u pages')));//重定向到facebook
}
其他的
{
//$con=$this->_getConnection();
//法师::帮手('Octopus/'))
$store=Mage::app()->getStore();$userId=$store->getName();
$db=Mage::getSingleton('core/resource')->getConnection(core_write);
$myformData=$this->getRequest()->getPost('myform');
$fbpost=$myformData['fbpost'];
如果(isset($fbpost))
{
echo Mage::helper('function')->test();
}
$couponId=$myformData['coupon_id'];
$coupontype=$myformData['优惠券类型'];
$select=$db->select();
$select->from('ops\u mobile\u优惠券')
->其中('id=?',$couponId);
$data=$db->fetchRow($select);
$select=$db->select()->from('ops_image_type_优惠券_details')->其中('优惠券id=?',$data['id');
$x=$db->fetchRow($select);
$image=$x['image_path'];
//->andWhere('client_id=?',$userId);
如果(isset($fbpost)和$coupontype=='image')
{
//Facebook形象启动
$app\u id=“app\u id”;
$app\u secret=“app\u secret”;
$facebook=新的facebook(数组)(
“appId”=>$app\u id,
'secret'=>$app\u secret,
“cookie”=>正确,
“fileUpload”=>true,
));
$accounts_list=$facebook->api('/me/accounts');
$accounts_list=$facebook->api('/me/accounts');
//获取作为页面发布的页面访问令牌
foreach($accounts_list['data']作为$account){
如果($account['id']='me'){//my page id=123456789
$access_token=$account['access_token'];
//echo“页面访问令牌:$Access_-Token”;
}
}
$attachment=array('消息'=>'图像优惠券',
“访问令牌”=>$access\u令牌,
'链接'=>'http://operture.com/jeegesh/index.php/octopus/adminhtml_coupon/postpart2/key/34f1bf523a35bc8c9213d669097f8e50/',
'source'=>$image,
);
$status=$facebook->api('/me/feed',POST',$attachment);//我的页面id=123456789
//var_dump($状态);
}
//图像Facebook结束}
您正在使用的重定向\u uri
是否与您在应用程序设置中为应用程序配置的URL匹配?否则,应用程序验证将失败,错误为191(非管理员将看不到具体原因)