 |
มีใครเขียนโปรแกรมที่ติดต่อกับ Facebook บ้างครับ อยากทราบวิธีแก้ไข Error ต่าง ๆ ของ Facebook SDK |
|
 |
|
|
 |
 |
|
ใช้ SDK ตัวไหนครับ ขอดูโค้ด ส่วน โพสหน่อยครับ จะชี้ชัดๆๆ ให้ครับ
|
 |
 |
 |
 |
Date :
2012-06-20 11:23:00 |
By :
lootboom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
require '../../lib/facebook-lib/src/facebook.php';
$facebook = new Facebook(array(
'appId' => _appId,
'secret' => _secret,
'cookie' => true,
));
$scopes = 'publish_stream, manage_pages, offline_access';
$user = $facebook->getUser();
$facebook->setFileUploadSupport(true);
$result = $db->getAllPostingPostJoinPostingPageByDatetimeAndApprovedStatus($next, $prev, _approved_status);
while($row = mysql_fetch_array($result))
{
postcontent($row['idPosting_Post'],$facebook);
}
function postcontent($post_id, $facebook)
{
$postdate = date("Y-m-d H:i:s");
$db = new DBCONTENTPOSTING();
$result = $db->getPostingPostJoinPostingPageByPostId($post_id);
$facebook->setAccessToken($result['Access_token']);
if($result['Post_Type'] == _post_photo_type)
{
$album = '';
if($result['Photo'] === 'old')
{
$album = $result['Album_FBID'];
}
else
{
//Create New Album
$args_album=array(
'name' => stripslashes($result['Album_Name']),
'message' => stripslashes($result['Album_Description'])
);
$newalbumid;
try
{
if($result['Album_Name']!="")
{
$newalbumid = $facebook->api('/'.$result['Page_FBID'].'/albums','post', $args_album); //Create new album
}
$album = $newalbumid['id'];
}
catch(FacebookApiException $e)
{
$db->addPostingErrorLog($post_id, $postdate, $e->getType(), $e->getMessage());
error_log($e);
}
}
$photolist = $db->getAllPostingPhotoByPostId($post_id);
$photoid = '';
$checkphoto = true;
while($row = mysql_fetch_array($photolist))
{
$args_photo = array(
'message' => stripslashes($row['Description']),
'source' => '@'.realpath($row['Path'])
);
try
{
if($row['Path'] != "")
{
$photoid = $facebook->api('/'.$album.'/photos','post', $args_photo); //add new photo
}
}
catch(FacebookApiException $e)
{
$photoid['id'] = '';
$db->addPostingErrorLog($post_id, $postdate, $e->getType(), $e->getMessage());
error_log($e);
$checkphoto = false;
}
//Upload Facebook Photo Id
$db->updatePostingPhotoByPhotoFbId($row['idPosting_Photo'], $photoid['id']);
}
if($checkphoto)
{
$status = $db->getPostingStatusByStatusName(_live_status);
}
else
{
$status = $db->getPostingStatusByStatusName(_failed_status);
}
if($db->updatePostingPostByPostFbIdAndPostingStatusId($post_id, null, $status['idPosting_Status']))
{
$db->updatePostingPostFbIdTagMap($post_id, "");
$output = 'Posted '.$status['Status_Name'];
}
else
{
$output = 'can not update status.';
}
echo $output;
}
}
โค้ดประมารนี้ครับ เพราะระบบมันใช้โพสเป็นรูปภาพซะส่วนใหญ่
|
 |
 |
 |
 |
Date :
2012-06-20 11:53:06 |
By :
st |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้อ ลืมบอกไปว่าใช้ Facebook SDK PHP น่ะครับ
|
 |
 |
 |
 |
Date :
2012-06-20 11:53:40 |
By :
st |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?php/** * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */require '../src/facebook.php';// Create our Application instance (replace this with your appId and secret).$facebook = new Facebook(array( 'appId' => '344617158898614', 'secret' => '6dc8ac871858b34798bc2488200e503d',));// Get User ID$user = $facebook->getUser();// We may or may not have this data based on whether the user is logged in.//// If we have a $user id here, it means we know the user is logged into// Facebook, but we don't know if the access token is valid. An access// token is invalid if the user logged out of Facebook.if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; }}// Login or logout url will be needed depending on current user state.if ($user) { $logoutUrl = $facebook->getLogoutUrl();} else { $loginUrl = $facebook->getLoginUrl();}// This call will always work since we are fetching public data.$naitik = $facebook->api('/naitik');?><!doctype html><html xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title>php-sdk</title> <style> body { font-family: 'Lucida Grande', Verdana, Arial, sans-serif; } h1 a { text-decoration: none; color: #3b5998; } h1 a:hover { text-decoration: underline; } </style> </head> <body> <h1>php-sdk</h1> <?php if ($user): ?> <a href="<?php echo $logoutUrl; ?>">Logout</a> <?php else: ?> <div> Login using OAuth 2.0 handled by the PHP SDK: <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> </div> <?php endif ?> <h3>PHP Session</h3> <pre><?php print_r($_SESSION); ?></pre> <?php if ($user): ?> <h3>You</h3> <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> <h3>Your User Object (/me)</h3> <pre><?php print_r($user_profile); ?></pre> <?php else: ?> <strong><em>You are not Connected.</em></strong> <?php endif ?> <h3>Public profile of Naitik</h3> <img src="https://graph.facebook.com/naitik/picture"> <?php echo $naitik['name']; ?> </body></html>
|
 |
 |
 |
 |
Date :
2012-06-20 18:58:08 |
By :
lkjhgfdsa258 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|