I have recently developed a facebook app using php. Though the app works in all browsers, it does not in Safari, it returns me to the first app step, after i try posting on a users wall. Following is my code.
My app displays a users friend list, and allows one to select friends, and post on their wall.
<?php
require ("facebook-api/src/facebook.php");
$facebook = new Facebook(array(
'appId' => '####',
'secret' => '####',
'cookie' => true,
));
// Login or logout url will be needed depending on current user state.
$params = array(
'scope' => 'email,user_birthday,friends_photos,publish_stream',
'redirect_uri' => 'https://apps.facebook.com/appname/'
);
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl($params);
}
$user = $facebook->getUser();
if ($user) {
$friends = $facebook->api('me/friends');
$uids = "";
foreach($friends as $f) {
$uids .= "uid=$f OR ";
}
$user_id_sess = $_SESSION['userid'];
$query_uids = substr($uids,0,strlen($query_uids)-4);
date_default_timezone_set('UTC');
$today = date('m\/d');
$data = $facebook->api(array('method'=>'fql.query','req_perms' => 'friends_birthday','query'=>"select uid,sex,name,birthday from user where uid in (select uid2 from friend where uid1=me()) ORDER by name ASC"));
echo "
<div class='span12 center-align' style='display:none;' id='block3'>
<form id='frmFb' name='frmFb' action='".$_SERVER['PHP_SELF']."' method='post' >
<p><img src='../static/images/logo.png' alt='logo' /></p>
<br />
<h1 style='margin-bottom:10px;'>Share with your friends</h1>
<p id='progress' style='display:none;'><img src='static/img/processing.gif' alt='Processing' /></p>
<div class='center-align well pull-center' style='max-height:300px; overflow:auto;'>
";
foreach($data as $today_bday) {
//$table='user_recipient';
$remfbid = $today_bday['uid'];
$fb_bday = $today_bday['birthday'];
echo "
<div style='width:50px; height:110px; margin:15px; float:left;' class='center-align'>
<a href='#' class='thumbnail'><img src='https://graph.facebook.com/".$today_bday['uid']."/picture' class='friend' alt='".$today_bday['name']."'></a>
<input type='checkbox' name='fbchoose[]' value='".$today_bday['uid']."'>
<p><small>".$today_bday['name']."</small></p>
<br/><br/>
</div>
";
}
echo "
</div>
<br />
<a href='#' class='btn btn-inverse btn-large'><i class='icon-ban-circle icon-white' style='margin-top:4px;'></i> CANCEL</a><input type='submit' value='SHARE NOW' name='btnAddReminder' class='btn btn-success btn-large' onclick='show()'>
</form>
</div>
";
} else {
echo "<p><script>top.location.href='$loginUrl';</script></p>
";
}
?>
<?
if(isset($_REQUEST['btnAddReminder'])){
if($_POST['fbchoose'] == "") {
$error_msg = "<div class='alert pull-center alert-error'><i class='icon-warning-sign' style='margin-top:2px;'></i> Please select at least one friend to share</div><br/>";
}
else {
foreach($_POST['fbchoose'] as $row) {
$vars = array(
'message' => 'Message...',
'name' => 'Name..',
'caption' => 'Caption',
'link' => 'Link',
'description' => 'Description',
'picture' => 'Picture...'
);
$facebook->api("/".$row ."/feed", 'post', $vars);
}
echo "<script>location.href='http://www.mywebsite.com/';</script>";
}
}
?>
in safari preferences, under "Privacy", set "Block cookies" to Never
Related
I try enable payment gateway Przelewy24 with Omnipay library for Codeigniter 3.
For this I install via composer both libraries.
Library:
https://github.com/mysiar-org/omnipay-przelewy24v1
and
https://github.com/thephpleague/omnipay
Then I create controller
Cart_contoller.php I add function
use Omnipay\Omnipay;
/**
* Payment with Przelewy24
*/
public function przelewy24_payment_post()
{
$przelewy24 = get_payment_gateway('przelewy24');
if (empty($przelewy24)) {
$this->session->set_flashdata('error', "Payment method not found!");
echo json_encode([
'result' => 0
]);
exit();
}
/** #var \Omnipay\Przelewy24\Gateway $gateway */
$gateway = Omnipay::create('Przelewy24');
$gateway->initialize([
'merchantId' => 'xxxx',
'posId' => 'xxxx',
'crc' => 'xxxxxxxxxxxx',
'testMode' => true,
]);
$params = array(
'sessionId' => 2327398739,
'amount' => 12.34,
'currency' => 'PLN',
'description' => 'Payment test',
'returnUrl' => 'www.xxxxxx',
'notifyUrl' => 'www.xxxxxxxxxxx',
'card' => array(
'email' => 'info#example.com',
'name' => 'My name',
'country' => 'PL',
),
);
$response = $gateway->purchase($params)->send();
if ($response->isSuccessful()) {
$response->redirect();
} else {
echo 'Failed';
}
}
in view page I add:
<?php echo form_open('cart_controller/przelewy24_payment_post'); ?>
<div class="payment-icons-container">
<label class="payment-icons">
<?php $logos = #explode(',', $payment_gateway->logos);
if (!empty($logos) && item_count($logos) > 0):
foreach ($logos as $logo): ?>
<img src="<?php echo base_url(); ?>assets/img/payment/<?= html_escape(trim($logo)); ?>.svg" alt="<?= html_escape(trim($logo)); ?>">
<?php endforeach;
endif; ?>
</label>
</div>
<button id="submit" class="btn btn-primary" id="card-button">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<?= trans("pay"); ?> <?= price_formatted($total_amount, $currency); ?>
</button>
<?php echo form_close(); ?><!-- form end -->
On button submit I get:
Type: Omnipay\Common\Exception\InvalidRequestException
Message: The email parameter is required
What I do wrong? Can anyone help me with this code how to correct integrate this gateway?
I have a php script below, to upload photo to facebook cover
<?php
if(is_single()){
if($_REQUEST['state']){
$imgsource = show_src('851','315');
}else{
$imgsource = $_POST['o'];
}
if($imgsource){
require_once "script/facebook.php";
$config = array(
'appId' => get_theme_option('app_id'),
'secret' => get_theme_option('secret'),
'fileUpload' => true,
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$photo = str_replace(home_url( '/' ),'',$imgsource);
$message = get_theme_option('descover');
if($user_id) {
try {
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . $photo,
'message' => $message,
)
);
$hasil3 = '<div id="modal-from-dom" class="modal hide fade">
<div class="modal-header">
×
<h2>You\'re almost done!</h2>
</div>
<div class="modal-body">
<img src="'.get_bloginfo("template_directory").'/images/eee.jpg" />
</div>
<div class="modal-footer">
Go to Facebook Profile
</div>
</div>
<button data-controls-modal="modal-from-dom" data-backdrop="true" data-keyboard="true" class="btn large success btnsingle">Preview Timeline</button>';
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
if($imgsource){header('Location: '.$login_url);}
}
}
}
?>
its not working now, because photo_upload permission in API depracated, how to fix this PHP script to working?
i already tried change photo_upload with these, but looks like still not right:
publish_stream
publish_actions
user_photos
I am gone mad since i cannot solve this.
Please help me. when i goto the php (Which is clixbox.net/fbupload.php)i created, after getting the user permissions, it gives me this error.
Fatal error: Uncaught OAuthException: Error validating application. Application has been deleted. thrown in /home/clixcube/public_html/clixbox.net/library/base_facebook.php on line 1271
my fbupload.php file is this
<?php
require_once 'library/facebook.php';
$facebook = new Facebook(array(
'this is where i put my app id' => $app_id,
'my app secret' => $app_secret,
'fileUpload' => true
));
//It can be found at https://developers.facebook.com/tools/access_token/
$access_token =
'this is where i put my token';
$params = array('access_token' => $access_token);
//The id of the fanpage
$fanpage = '232241216922182';
//The id of the album
$album_id ='281594988653471';
//Replace Wa33D94 with your Facebook ID
$accounts = $facebook->api('/Wa33D94/accounts', 'GET', $params);
foreach($accounts['data'] as $account) {
if( $account['id'] == $fanpage || $account['name'] == $fanpage ){
$fanpage_token = $account['access_token'];
}
}
$valid_files = array('image/jpeg', 'image/png', 'image/gif');
if(isset($_FILES) && !empty($_FILES)){
if( !in_array($_FILES['pic']['type'], $valid_files ) ){
echo 'Only jpg, png and gif image types are supported!';
}else{
#Upload photo here
$img = realpath($_FILES["pic"]["tmp_name"]);
$args = array(
'message' => 'This photo was uploaded via Clixbox.net',
'image' => '#' . $img,
'aid' => $album_id,
'no_story' => 1,
'access_token' => $fanpage_token
);
$photo = $facebook->api($album_id . '/photos', 'post', $args);
if( is_array( $photo ) && !empty( $photo['id'] ) ){
echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to see this photo on
Facebook.</a></p>';
}
}
}
?>
<html>
<head>
<title>Upload a picture to facebook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<!-- Form for uploading the photo -->
<div class="main">
<p>Select a photo to upload on Facebook Fan Page</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
</body>
</html>
And the base_facebook.php line (1271) is this
$e = new FacebookApiException($result);
Any idea on how to solve this?
Consider checking in your application list to see if the application is still there
developers.facebook.com/apps
If it is, consider submitting a bug developers.facebook.com/bugs
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
PHP SCRIPT issue with passing the uploaded image to facebook->api function
I have this code and its working awsomely fine just and just only one problem i am not able to pass my uploaded image to facebook->api (whether its valid or not) and the following always echo
echo 'Only jpg, png and gif image types are supported!';
i even remove the check on image type and try to get the image from
$img = realpath($_FILES["pic"]["tmp_name"]);
but $img gets nothing in it and uploads a by default empty image on facebook as my page
Kindly check my following code and let me know what should is wrong with my code so i'll become able to upload images
<?
require 'src/facebook.php';
$app_id = "364900470214655";
$app_secret = "xxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'fileUpload' => true,
));
$user = $facebook->getUser();
//echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
$valid_files = array('image/jpeg', 'image/png', 'image/gif');
//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
if($account['id'] == 194458563914948){ // my page id =123456789
$access_token = $account['access_token'];
echo "<p>Page Access Token: $access_token</p>";
}
}
//posting to the page wall
if (isset($_FILES) && !empty($_FILES))
{
if( !in_array($_FILES['pic']['type'], $valid_files ) )
{
echo 'Only jpg, png and gif image types are supported!';
}
else{
#Upload photo here
$img = realpath($_FILES["pic"]["tmp_name"]);
$attachment = array('message' => 'this is my message',
'access_token' => $access_token,
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'example.org',
'description' => 'this is a description',
'picture' => '#' . $img,
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$status = $facebook->api('/194458563914948/feed', 'POST', $attachment); // my page id =123456789
var_dump($status);
}
}
?>
<body>
<!-- Form for uploading the photo -->
<div class="main">
<p>Select a photo to upload on Facebook Fan Page</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
</body>
Creating a New Album and Adding a Photo
This is the scenario where you upload a photo to the ALBUM_ID/photos Graph API endpoint. The user interface for this example allows the user to select a photo and add a caption before submitting the new photo.
Using PHP:
<?php
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$post_login_url = "YOUR_POST-LOGIN_URL";
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if(empty($code))
{
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url .
"'</script>");
}
else {
$token_url= "https://graph.facebook.com/oauth/"
. "access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Create a new album
$graph_url = "https://graph.facebook.com/me/albums?"
. "access_token=". $access_token;
$postdata = http_build_query(
array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false,
$context));
// Get the new album ID
$album_id = $result->id;
//Show photo upload form and post to the Graph URL
$graph_url = "https://graph.facebook.com/". $album_id
. "/photos?access_token=" . $access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url. ' "method="POST">';
echo 'Adding photo to album: ' . $album_name .'<br/><br/>';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message" type="text"
value=""><br/><br/>';
echo '<input type="submit" value="Upload" /><br/>';
echo '</form>';
echo '</body></html>';
}
?>
I have the following code:
$facebook = new Facebook(array(
'appId' => 'id',
'secret' => 'secret',
));
$user = $facebook->getUser();
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'req_perms' => 'email,user_birthday,user_about_me'
));
}
and HTML:
<a class="button-fb" href="<?php echo $loginUrl; ?>" title="Connect with Facebook">Connect with Facebook</a>
The problem is that the <a> will open in the current page, I want to open in a popup (like most site do). How to do? =)
You can use this snippet to create a popup.. It uses Javascript.
<a class="button-fb" href="javascript: void(0)"
onclick="window.open('<?php echo $loginUrl; ?>',
'windowname1',
'width=200, height=77');
return false;" title="Connect with Facebook">Connect with Facebook</a>
I hope this helps.