duandan4680 2012-06-13 12:49
浏览 47

Facebook用户在自己的网站上使用应用程序时的权限 - 集成在PHP而不是Url中

I created a Facebook App using PHP on my website. To use this application on my website the user must login using Facebook authentication.

This app basically lets the user post a default comment on his wall. It works fine using my facebook profile account, but when I asked my friend to use my site he gets the following error - 'Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in'

The only solution to my problem i found till now is by entering the following URL - <pre>https://www.facebook.com/login.php?api_key=API_KEY&cancel_url=http://www.magimagi.com&next=http://magimagi.com/login/uploadtopage2.php&fbconnect=1&return_session=1&session_version=3&v=1.0&display=page&req_perms=user_about_me,user_birthday,publish_stream,offline_access</pre>

I do not want to create a link on my app for the user to click it - instead I want it integrated into the PHP code already on my website.

Here is a sample PHP code I have

<pre>

/ Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(   array(
       'scope' => 'publish_stream'
      ));
}
</pre>

This is the HTML

<pre>
<form id="selectFriend" name="selectFriend" method="post">
<label for="Friend">Friend:</label>
<select id="friend" name="friend">
<?php 
foreach($user_friends['data'] as $f){
echo '<option value="'.$f['id'].'">'.$f['name'] .'</option>';
} 
?>
</select>
<label for="URL">URL:</label>
<input id="link" name="link">
<input id="message" name="message">
<input type="submit" name="submit" id="submit" value="Send!">
</form>

  • 写回答

2条回答 默认 最新

  • duan5731 2012-06-13 13:07
    关注

    I just tried this in Graph Explorer, it seems that in order to get information from /me, you need to pass access token (i don't remember it being this way before). Using user's id instead if /me, works just fine and returns basic information without access token. You could also try passing access token with your current request:

    $token = $facebook->getAccessToken();
    $user_profile = $facebook->api('/me',array (
    'access_token' => $token)
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?