2011-12-08 44 views
3

標籤的用戶我一個嘗試寫一個腳本,可以讓用戶標記自己在我的網站上顯示的照片。不能在Facebook頁面PHP SDK圖形API

一旦用戶選擇了要標記的人,照片就會上傳到我網站的Facebook粉絲頁面,但Facebook不會允許我的應用使用當前登錄的用戶profile_id或任何他們的朋友們。

一切從添加標籤偉大的工作APPART。我收到錯誤: 致命錯誤:未捕獲OAuthException:發生未知錯誤。拋出/home/public_html/include/api/facebook.3.0.1/base_facebook.php上線1039

這是迄今爲止代碼:

<?php 
require_once ($_SERVER['DOCUMENT_ROOT'] . "/include/api/facebook.3.0.1/facebook.php"); 

//Name of album you want to create 
$album_name = "December 4, 2011"; 

// Create our application instance 
// (replace this with your appId and secret). 
$facebook = new Facebook(array(
     'appId' => 'APP_ID_INSERT_HERE', 
     'secret' => 'APP_SECRET_INSERT_HERE', 
    )); 

$facebook->setFileUploadSupport(true); 


// 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; 
    } 
} 

if ($user) { 

// Get access token for Facebook Page 
$page_id = '170367249680012'; 
$page_info = $facebook->api("/$page_id?fields=access_token"); 

if (!empty($page_info['access_token'])) { 

    $param = array(
     'method' => 'fql.query', 
     'query' => 'SELECT object_id FROM album WHERE owner="FACEBOOK_PAGE_ID_INSERT_HERE" AND name="' . $album_name . '"' 
    ); 
    //Check if album exists 
    $album = $facebook->api($param); 

    if (isset($album[0]['object_id'])) { 
     // If album exists store id in the variable $album_uid 
     $album_uid = $album[0]['object_id']; 
    } else { 

     // ELSE Create album 
     $album_details = array(
      'access_token' => $page_info['access_token'], 
      'message' => 'Album desc', 
      'name' => $album_name 
     ); 

     $create_album = $facebook->api('/me/albums', 'post', $album_details); 

     //Get album ID of the album you've just created 
     $album_uid = $create_album['id']; 
    } 

    //Photo Details 

    $file = 'test.jpg'; //Example image file 
    $photo_details['image'] = '@' . realpath($file); 

    //Upload a photo to album 

    $args = array(
     'access_token' => $page_info['access_token'], 
     'image' => '@' . realpath($file), 
     'message' => "test" 
    ); 


    $upload_photo = $facebook->api('/' . $album_uid . '/photos', 'post', $args); 

    //Get id of photo uploaded 
    $photo_id = $upload_photo['id']; 

    echo "<br/>" . $photo_id . "<br/>"; 


//ADD TAGS 

    $argstag = array('to' => $user); 
    $argstag['x'] = 40; 
    $argstag['y'] = 40; 
    $datatag = $facebook->api('/' . $photo_id . '/tags', 'post', $argstag); 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(array('scope' => 'status_update,publish_stream,user_photos,offline_access,manage_pages')); 
} 

?> 
<!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 ?> 

    </body> 
</html> 

有趣的是,如果我用同樣的腳本將圖像上傳到用戶配置文件並標記它工作的圖像!

對於那些你們誰想要做到這一點刪除下面的代碼行出現兩次 'ACCESS_TOKEN'=> $ page_info [ 'ACCESS_TOKEN'],

,並更改 $ upload_photo = $ facebook-> api('/'。$ album_uid。'/ photos','post',$ args);

到 $ upload_photo = $ facebook-> api('/ me/photoshop','POST',$ args);

我搜索了高和低,看看是否有限制停止API允許用戶在粉絲頁上標記自己或朋友,但我找不到任何東西。我能找到的唯一的事情是這樣的:

http://forum.developers.facebook.net/viewtopic.php?id=101485

所以我不知道這是否是offically一個錯誤,但我似乎因爲它們有同樣的問題是具有。它在6個月前被提交爲bug,似乎沒有任何進展。

有沒有人知道這個問題的解決方法?我不想將圖片上傳到用戶個人資料並對其進行標記。

回答

1

檢查您的頁面設置。有一種設置可以讓粉絲在照片中標記自己。確保已啓用並重試。查找Manage Permissions下的Tagging Ability設置。