Commits

Gaurav Toshniwal committed 5423540

Trying facebook post

Comments (0)

Files changed (5)

cards/98127398.png

Old
Old image
New
New image
 if ($user) {
   $logoutUrl = $facebook->getLogoutUrl();
 } else {
-  $loginUrl = $facebook->getLoginUrl();
+  $loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_stream,' , ));
 }
 
 // This call will always work since we are fetching public data.
 	var side1Context = side1Canvas.getContext('2d');
 	var src     = layer2.toDataURL("image/png"); // cache the image data source
     var img     = document.createElement('img'); // create a Image Element
-    img.src     = src;   //image source
+    img.src     /= src;   //image source
 	side1Context.drawImage(img,0,0);
 	//showCanvasSide(sideContext);
 }
 var image_data;
 function proceedToSides() {
 	//set session data as image data
+	image_data = layer2.toDataURL();
 	$.ajax({
 	  type: "POST",
 	  url: "session.php?f=createsessiondata",
 		finished_side_one_context.drawImage(layer2,cropping_area_bounds.tl.x,cropping_area_bounds.tl.y,cropping_area_size.x,cropping_area_size.y,0,0,cropping_area_size.x*scale_of_displayed_image,cropping_area_size.y*scale_of_displayed_image);
 		body.appendChild(finished_side_one);
 		body.insertBefore(document.getElementById('fblinks'));
-		image_data = layer2.toDataURL();
 		console.log(image_data);
 		//remove the original canvas division itself
 		document.getElementById('cropping').parentElement.removeChild(document.getElementById('cropping'));
 		finished_side_one_context.drawImage(image,cropping_area_bounds.tl.x,cropping_area_bounds.tl.y,cropping_area_size.x,cropping_area_size.y,0,0,cropping_area_size.x*scale_of_displayed_image,cropping_area_size.y*scale_of_displayed_image);
 		body.appendChild(finished_side_one);
 		body.insertBefore(document.getElementById('fblinks'));
-		image_data = layer2.toDataURL();
+		createSideTwo();
+		//image_data = layer2.toDataURL();
 	});
 
 	//remove the original canvas division itself
 	document.getElementById('cropping').parentElement.removeChild(document.getElementById('cropping'));
 
-	createSideTwo();	
 }
 
 function uploadFileToServer() {
   //data: { image_data: image_data, emp : employee.id},
   //beforeSend: function(xhr){xhr.setRequestHeader('Content-Type', 'application/upload');}
 }).done(function( msg ) {
-  if (msg) proceedToSidesDirectly();
-  else init();
+	//console.log(msg.length);
+	if (msg.length) proceedToSidesDirectly();
+	else init();
 });
 
 
 	<a href="#" onclick="destroySession()">Recreate the card</a>
 	<a href="#" onclick="uploadFileToServer()">Submit for Printing</a>
 	    <?php if ($user): ?>
-	      <a href="<?php echo $logoutUrl; ?>">Logout</a>
+	        <a href="post.php"> Post to Facebook </a>
+		<a href="<?php echo $logoutUrl; ?>">Logout</a>
 	    <?php else: ?>
 	      <div>
 	        Login using OAuth 2.0 handled by the PHP SDK:
+<?php
+require 'scripts/facebook.php';
+$your_base64_string=$_SESSION['image_data'];
+function base64_to_jpeg( $base64_string, $output_file ) {
+  $ifp = fopen( $output_file, "wb" ); 
+  fwrite( $ifp, base64_decode( $base64_string) ); 
+  fclose( $ifp ); 
+  return( $output_file ); 
+}
+$facebook = new Facebook(array(
+  'appId'  => '382132615191193',
+  'secret' => 'ce402aee16df3ff392656f4fd6678a53',
+
+));
+$facebook->setFileUploadSupport(true);
+$image = base64_to_jpeg( $your_base64_string, 'tmp.jpg' );
+$args = array('message' => 'Some message');
+echo realpath($image);
+$args['image'] = '@' . realpath( $image );
+$data = $facebook->api('/764598205/photos', 'post', $args);
+unlink($image);
+?>
 }
 function getsessiondata() {
 	session_start();
-	if (isset($_SESSION['image_data']));
-	echo $_SESSION['image_data'];
+	if (isset($_SESSION['image_data'])) {
+		echo $_SESSION['image_data'];
+	}
 }
 function destroysession() {
 	session_start();

tmp.jpg

Added
New image