Post photo into facebook album with php -
Post photo into facebook album with php -
i'm trying post photo url fb , after reading , reading not able create work. here code, took on web:
<?php error_reporting(e_all & ~e_notice); $app_id = "316094425259906"; $app_secret = "1610877d611967f77ba4e677c851eb75"; $my_url = "http://www.cdn-coins.com/ccdatabase/eng/fb7.php"; // mainly, redirect page $perms_str = "publish_stream"; $code = $_request["code"]; if(empty($code)) { $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=" . $perms_str; echo("<script>top.location.href='" . $auth_url . "'</script>"); } $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code; $response = file_get_contents($token_url); $p = null; parse_str($response, $p); $access_token = $p['access_token']; $graph_url= "https://graph.facebook.com/me/photos?" . "access_token=" .$access_token; if (!empty($_files)) { $params = array(); if( isset($_post['message']) ) { $params['message'] = trim($_post['message']); } $uploaddir = './uploads/'; // upload folder $uploadfile = $uploaddir . basename($_files['source']['name']); if (move_uploaded_file($_files['source']['tmp_name'], $uploadfile)) { $params['source'] = "@" . realpath($uploadfile); } // start graph api phone call $ch = curl_init(); curl_setopt($ch, curlopt_url,$graph_url); /* next alternative used user local (wamp) machine. should removed when used on live server! refer:https://github.com/facebook/php-sdk/issues/7 */ curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_postfields, $params); $result = curl_exec($ch); $decoded = json_decode($result, true); curl_close($ch); if(is_array($decoded) && isset($decoded['id'])) { /* image uploaded successfully: 1) show success message 2) optionally, delete image our server */ $msg = "image uploaded successfully: {$decoded['id']}"; } } ?> <!doctype html> <html> <head> <title>upload</title> <style> label {float: left; width: 100px;} input[type=text],textarea {width: 210px;} #msg {border: 1px solid #000; padding: 5px; color: red;} </style> </head> <body> <?php if( isset($msg) ) { ?> <p id="msg"><?php echo $msg; ?></p> <?php } ?> <form enctype="multipart/form-data" action="" method="post"> <p><label for="name">caption</label><input type="text" name="message" value="" /></p> <p><label for="source">photo</label><input type="file" name="source" /></p> <p><input type="submit" value="upload" /></p> </form> </body> </html>
it supposed load photo, doesnt , dont have $msg ned, nothing.
thanks helping me.
php
Comments
Post a Comment