Ex1t Posted August 9, 2015 Share Posted August 9, 2015 I have image upload script, now i want that when I upload new image to my site to share automatically on facebook page, can i make some simple script for that operation? Can someone give me simple code for that? Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/ Share on other sites More sharing options...
QuickOldCar Posted August 9, 2015 Share Posted August 9, 2015 Facebook has their sdk, app, and tokens to share on their site. https://developers.facebook.com/docs/reference/php/5.0.0 Then there is the sharing. https://developers.facebook.com/docs/sharing/web Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518354 Share on other sites More sharing options...
Ex1t Posted August 10, 2015 Author Share Posted August 10, 2015 Yeah i checked that, but i dont know how to implement that in my code.. Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518412 Share on other sites More sharing options...
maxxd Posted August 10, 2015 Share Posted August 10, 2015 No one is going to give you the code - coding is what most of us get paid to do. Start with the APIs and documentation that QuickOldCar link to above, Google, and try some things. When you get stuck, come on here and tell us what you've tried, show us the code you've written, and we'll help where we can. Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518417 Share on other sites More sharing options...
Ex1t Posted August 10, 2015 Author Share Posted August 10, 2015 Okay, so i dont know to work with API but im tryingSo this is my simple code <form action="" method="post"> <input type="file" name="fileToUpload"> <button>Upload</button> </form> <?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { $fb = new Facebook\Facebook([ 'app_id' => 'myappid', 'app_secret' => 'myappsecret', 'default_graph_version' => 'v2.4', ]); $data = [ 'message' => 'My awesome photo upload example.', 'source' => $fb->fileToUpload($target_dir), ]; try { // Returns a `Facebook\FacebookResponse` object $response = $fb->post('/me/photos', $data, 'myaccesstoken'); } catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } $graphNode = $response->getGraphNode(); echo 'Photo ID: ' . $graphNode['id']; echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } ?> I got this error message Notice: Undefined index: fileToUpload in C:\wamp\www\fb.php on line 10 What is wrong in code for upload?Btw. are code for facebook API good? Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518421 Share on other sites More sharing options...
Ex1t Posted August 10, 2015 Author Share Posted August 10, 2015 I fixed last error, but I got this error now Fatal error: Class 'Facebook\Facebook' not found in C:\wamp\www\fb_upload.php on line 223 Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518424 Share on other sites More sharing options...
ginerjm Posted August 10, 2015 Share Posted August 10, 2015 1 - you are using $_POST in your code but since your form doesn't have a method set the $_POST array won't have your inputs 2 - You also reference an input name of 'submit' but I don't see that in your form 3 - I don't see where you included the class so that could certainly explain your new error now as well as the above two items. 4 - add php error checking to help you debug what will probably be many future errors. See my signature. Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518425 Share on other sites More sharing options...
Ex1t Posted August 10, 2015 Author Share Posted August 10, 2015 I have included now all required files from https://github.com/facebook/facebook-php-sdk-v4 But i still get some errors, i have fix it 1 by 1 but still and still getting new errors for including and others.. Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518429 Share on other sites More sharing options...
ginerjm Posted August 11, 2015 Share Posted August 11, 2015 Did you fix the problems I pointed out? When you do how about isolating the new problem area(s) and posting those snippets of code for us to address? I, for one, will not be going to your external post no matter where it is hosted, so I won't be any help until you do the necessary work to get close to your problem and ask a pertinent question. Link to comment https://forums.phpfreaks.com/topic/297697-upload-and-share/#findComment-1518478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.