I was using CURL to publish on Facebook page but now it's not working anymore.
I need to publish on Facebook page using GraghAPI and CURL from my website to my pages.
This was code used before it was working for about 4 months ago but now not working:
$page_access_token = 'PAGE_ACCESS_TOKEN';
$page_id = 'PAGE_ID';
$data['picture'] = $news_image;
$data['link'] = $url_link;
$data['message'] = $title;
$data['caption'] = $title;
$data['description'] = $disc;
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/' . $page_id . '/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
How to publish to Facebook page without using Facebook App as it need a lot of verification to make an app.
Related
I can use the API to post to my facebook following the example at Simple example to post to a Facebook fan page via PHP?, as below
$data['picture'] = $image_URL;
$data['link'] = $link_URL;
$data['message'] = $message_TEXT;
$data['caption'] = $caption_TEXT;
$data['description'] = $description_TEXT;
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
}catch (Exception $e) {
echo 'ERROR '.$e.' in CURL for Facebook posting';
}
Is it possible to do something similar to share a post, if we know the URL of the post (e.g. https://www.facebook.com/TED/posts/10159368542595652)
Does anyone know if its possible to create a Facebook notification either via Vb.Net or PHP using the Facebook SDK version 4.
Ideally I'd like to have users on my website enter their Facebook login details which I'd then store their [facebook id] so I could send a weekly status notification via VB.Net to their Facebook account.
Edited
So far I get the scope ID from javascript and for testing copy it to PHP
<?php
$appId = '77585851581xxxx';
$appSecret = 'xxxx';
$userId = '1015273548332xxxx'; //Scope ID
$accesstoken = $appId . '|' . $appSecret;
$notificationText = 'The cake is a lie.';
//Get Access Token
$args = array('grant_type' => 'client_credentials',
'client_id' => $appId,
'client_secret' => $appSecret);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$returnValue = curl_exec($ch);
curl_close($ch);
echo $returnValue;
$accesstoken = $returnValue;
//Set Notification
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook');
$url = 'https://graph.facebook.com/' . $userId . '/notifications' .
'?access_token=' . $accesstoken .
'&template=' . $notificationText .
'&href=';
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
echo $curlResult;
?>
I now get the error:
Sorry, something went wrong. We're working on getting this fixed as soon as we can.
Tutorial for the PHP SDK 4.0: http://www.devils-heaven.com/facebook-php-sdk-4-0-tutorial/
Although i would suggest using simple CURL calls for App Notifications, you donĀ“t need the PHP SDK for that. Example code can be found here: http://blog.limesoda.com/2014/08/app-notifications-facebook-apps/
The article is in german, but the code is the relevant part:
$accessToken = $appId . '|' . $appSecret;
$notificationText = 'The cake is a lie.';
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook');
//send notification
$url = 'https://graph.facebook.com/' . $userId . '/notifications' .
'?access_token=' . $accesstoken .
'&template=' . $notificationText .
'&href=';
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
I am using PHP and cURL to login through a HTML login form and grab the page that it redirects to. Unfortuntley I get a 'File Not Found'. I am not being logged in correctly, despite giving the right information. I have checked the form layout at lobby.cloudtrax.com to ensure I am posting all the data needed. You can only reach /vouchers/edit_vouchers.php if you are logged in otherwise you get a File Not found.
$username = urlencode("xxxxx");
$password = urlencode("xxxxx");
$cloudtrax_base = "https://lobby.cloudtrax.com";
$loginurl = "vouchers/edit_vouchers.php";
$postdata = "account=".$username."&password=".$password."&edit=Login";
$cookie = "cloudtrax-cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cloudtrax_base);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
//Execute the action to login
$postResult = curl_exec($ch);
if($postResult === FALSE) {
echo "cURL error:" . curl_error($ch);
}
curl_setopt($ch, CURLOPT_URL, "$cloudtrax_base/$loginurl");
$res = curl_exec($ch);
print_r($res);
curl_close($ch);
Using HTTP Headers I find that once curl logs in it get redirected to https://lobby.cloudtrax.com/vouchers/dashboard.php.
But when I log in through the browser using the same user/pass I get redirected to https://lobby.cloudtrax.com/vouchers/edit_vouchers.php which is what I want to copy
Any reason this doesn't work??
<?php
$username = "xxxx";
$password = "xxxx";
$name="test";
$voucher="zx9kjspo";
$duration = 4368;
$down = 4.5;
$up = 2;
$maxusers = 3;
$loginurl = "https://lobby.cloudtrax.com/lobby.php";
$voucherurl = "https://lobby.cloudtrax.com/vouchers/vouchers2.php";
exec("curl -s -L -e https://lobby.cloudtrax.com/lobby.php -c cloudtrax-lobby-cookies.txt -X POST -d 'account=" . urlencode($username) . "&password=" . urlencode($password) ."&edit=Login' $loginurl");
passthru("curl -s -o output.txt -e https://lobby.cloudtrax.com/vouchers/edit_vouchers.php -c cloudtrax-lobby-cookies.txt -b cloudtrax-lobby-cookies.txt -X POST -d 'voucher_code=" . urlencode($voucher) . "&comment=" . urlencode($name) . "&duration=" . urlencode($duration) . "&max_users=" . urlencode($maxusers) . "&downValue=" . urlencode($down) . "&upValue=" . urlencode($up) . "&valid=Hours+Valid&login=Login+Code&border=0&logo=0&submit=Create+Vouchers' $voucherurl");
?>
Make sure you are POST'ing to the actual login URL and not relying on a redirect (ie include lobby.php in the login URL):
$loginUrl = 'https://lobby.cloudtrax.com/lobby.php'; //action from the login form
$loginFields = array('account'=>'account', 'password'=>'pass', 'edit'=>'Login'); //login form field names and values
$voucherUrl = 'https://lobby.cloudtrax.com/vouchers/edit_vouchers.php';
$login = getUrl($loginUrl, $loginFields); //login to the site
$voucherPage = getUrl($voucherUrl); //get the voucher page
function getUrl($url, $postVars='') {
$ch = curl_init();
if (!empty($postVars)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cloudtrax-cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cloudtrax-cookie.txt');
$buffer = curl_exec($ch);
curl_close($ch);
return $buffer;
}
I'm using PHP to request a secure token from the Paypal server to call a hosted page. I have followed the directions on https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pages/ to add a user to my Paypal Advanced account and have set up the Hosted Checkout Page as indicated. I have used layout C but changing to A or B doesn't change anything.
The code I am using to request the token is as follows:
$url = 'https://payflowpro.paypal.com';
$token = md5('saltedtobechangedlater' . time() );
$info = "PARTNER=paypal&
VENDOR=[my merchant login]&
USER=[username I created]&
PWD=[password I assigned]&
TRXTYPE=S&
CURRENCY=USD&
AMT=1.00&
CREATESECURETOKEN=Y&
MODE=TEST&
SECURETOKENID=$token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $info);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch) ;
$info = curl_getinfo($ch);
curl_close($ch);
if( $err ){
echo "<pre>Error. $err\n$errmsg\n";
print_r($info);
echo '</pre>';
}
echo $content;
The response is: "RESULT=1&RESPMSG=User authentication failed". I have made sure that my hosted page is set as test.
I am trying to login Joomla 1.6/3.0 by curl in PHP but not success.
I had try method from joomla 1.5
$uname = "id";
$upswd = "pswd";
$url = "http://www.somewebpage.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, FALSE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}
// POST fields
$postfields = array();
$postfields['username'] = urlencode($uname);
$postfields['passwd'] = urlencode($upswd);
$postfields['lang'] = '';
$postfields['option'] = 'com_login';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
But it 's show forbidden
Joomla! normally from the web browser will send a token, to make sure the form was posted from a browser (and not from somewhere outside, like you are trying to do).
If it's not posted from a browser, an error like 'The most recent request was denied because it contained an invalid security token. Please refresh the page and try again.'
You may want to look for an autentication plugin that supports what you are trying to do. For example the Autologin plugin.