-1

我正在我的应用程序中集成 facebook 登录,一切正常。我现在想要两件事。

  1. 我希望每当有新用户出现并单击“使用 facebook 登录”时,在所有过程之后,应该在该用户墙上发布一个帖子,该用户已开始使用我的应用程序链接到应用程序..就像我们看到的那些游戏,比如“<用户>开始使用德州扑克”

  2. 获取用户头像...

这是它的链接http://oauth.netne.net/index.php

我怎样才能做到这一点?

4

2 回答 2

1

在用户的墙上发帖:

使用 Javascript:

    function doPost() {
    var params = {};
    params['message'] = "<USER> started using <YOUR APP NAME>";
    params['name'] = '<YOUR APP NAME>';
    params['description'] = '<DESCRIPTION ABOUT YOUR APP>';
    params['link'] = "<LINK TO YOUR WEBSITE>";
    //ON CLICKING THE POST WHERE YOU WANT USER  TO BE REDIRECTED e.g. www.yoursite.com
    params['picture'] = '<PATH OF PICTURE THAT YOU WANT TO BE DISPLAYED ON THE POST>';
    FB.api('/me/feed', 'post', params, function(response) {
        if(!response || response.error) {
            console.log('ERROR OCCURED '+response.error);
        }
        else {
            console.log('POSTED SUCCESSFULLY');
        }
    }}

使用 PHP:

$ret_obj = $facebook->api('/me/feed', 'POST',
       array( 'link' => '<LINK TO YOUR WEBSITE>',
              'message' => '<USER> started using <YOUR APP NAME>',
              'description' => "<DESCRIPTION ABOUT YOUR APP>")); //Returns the POST ID.

获取用户图像:

$fbImageUrl = https://graph.facebook.com/**<FBUSER_ID>**/picture?type=<VALUE>(或者)

$fbImageUrl = https://graph.facebook.com/**<FBUSER_NAME>**/picture?type=<VALUE>

哪里可以是“小”或“正常”或“大”或“方形”。

//保存图片:

$localFilePath = 'pathToImagesFolder/<SOME_NAME>.jpg'; //Use relative path.
$fbImage = file_get_contents($fbImageUrl); //Fetches the image and stores it in variable.
file_put_contents($file1, $img1); //Will save the image in the path specified.
于 2013-03-16T10:48:20.170 回答
0

是的,你必须处理这种情况。如果用户没有授予访问权限试试这个:

  try {
        $ret_obj = $facebook->api('/me/feed', 'POST',
        array( 'link' => '<LINK TO YOUR WEBSITE>',
               'message' => '<USER> started using <YOUR APP NAME>',
               'description' => "<DESCRIPTION ABOUT YOUR APP>"));

      } catch(FacebookApiException $e) {
        $login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
        header("Location: $login_url"); 
      }

但是,如果他们被连续重定向,这会惹恼用户。所以最好跳过这一步,而不是强迫用户接受它。请记住,您应该在注册时提供所需的所有范围。

于 2013-03-16T12:33:15.670 回答