 |
รบกวนถามเรื่องโพสรูปบน wall ของ facebook หน่อยอะครับ |
|
 |
|
|
 |
 |
|
เอาโค้ดมาจากในเน็ตอ่าครับ
เหมือนว่ามันไม่มีค่า $user_id อ่าครับ มันข้ามไปที่ else เลย
ขอบคุณล่วงหน้าครับ
Code
require_once('src/facebook.php');
$config = array(
'appId' => '522168587812019',
'secret' => 'c565e22e0c122a762ad453c9bf41453a',
'fileUpload' => true,
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$photo = $mpic; // Path to the photo on the local filesystem
$message = $mms;
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '@' . $photo,
'message' => $message,
)
);
echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo 'Please <a href="' . $login_url . '">login</a>';
}
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2012-10-20 23:57:37 |
By :
framewin |
View :
868 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เชื่อมต่อปกติ แบบ ไม่ต้องโพสรูป คุณ connect ได้หรือยังครับ
|
 |
 |
 |
 |
Date :
2012-10-21 12:08:42 |
By :
progamer2000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|