1

我无法让用户将应用请求转发给他的朋友;

我在客户端使用下一个代码:

window.fbAsyncInit = function() {
    FB.init({
        appId: 'FBAPPD',
        frictionlessRequests: true,
        status     : true,
        cookie     : true,
        xfbml      : true
    });
};

当用户选择她的朋友时:

function sendRequestToRecipients() {
var user_ids = document.getElementById("request_ids").value; //ID_user1,ID_user2...
 FB.ui({
        method: 'apprequests',
        message: 'Prueba una nueva forma de comunicarte con tus contactos...',
        to: '' + user_ids + '',
    }, requestCallback);

function requestCallback(response) {
// Handle callback here
    if (response.request && response.to) 
    {
        var request_ids = [];
        for(i=0; i<response.to.length; i++) {
            var temp = response.request + '_' + response.to[i];
            request_ids.push(temp);
        }
        var requests = request_ids.join(',');
        $.post('/FB_Invitaciones', { uid: document.getElementById("FBUser").value, request_ids: requests }, function (resp) {
            // callback after storing the requests
        });
    } else 
    {
        alert('canceled');
    }
}

服务器端

<?php
[...]
    $token_url = "https://graph.facebook.com/oauth/access_token?" .
        "client_id=" . $FBAPPID .
        "&client_secret=" . $FBSECRETFBAPPID .
        "&grant_type=client_credentials";

    $app_access_token = file_get_contents($token_url);

    $user_id = $datos->getFBID();

    //Procesando ids 
    $ids = explode(",",$_REQUEST['request_ids']);

    foreach($ids as $request)
    {
        $apprequest_url ="https://graph.facebook.com/" .$request.
            "?".$app_access_token;
        $result = file_get_contents($apprequest_url);
    }
die()
?>

我找不到错误。

谢谢您的帮助

4

2 回答 2

0

我在这个问题中找到了解决方案: 发送应用请求有效,但未发送给用户? 在我的应用程序配置中,我需要检查“Facebook 上的应用程序”,现在可以正常工作

于 2012-05-17T07:38:08.503 回答
-1

@gokuhs 复制过去并尝试这个 1 工作得很好...将设计更改为您的要求还输入您的应用程序 ID 和密码,但从检索部分我遇到问题...如果有人提供解决方案我准备付款甚至,我可以提供我的 ftp 和 facebook 登录详细信息

 <?php
    session_start();
    if(!empty($_REQUEST['request_ids'])) {
    require_once('src/facebook.php');

    $config = array();
    $config["appId"] = "XXXXXXX";
    $config["secret"] = "XXXXXXX";
    $config["fileUpload"] = false; // optional

    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $config["appId"],
      'secret' => $config["secret"],
      'cookie' => true,
    ));

        echo $user_id= $facebook->getUser();

        // Here I want to retreive Type, color and message.

    }

    else{

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script src="js/jquery-1.6.2.min.js" type="text/javascript" ></script>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <title>Greetings</title>

    </head>

    <body>

    <div align="center"> </div>
    <div class="main">

    <div style="margin-left:300px; width:540px; margin:auto;">

    <table>
    <tr>
        <td height="39">
            <span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Type :</span>
        </td>
        <td>
            <select id="catag">
                <option>Love</option>
                <option>Friend</option>
                <option>Mother</option>
                <option>Father</option>
            </select>
        </td>
        <td>

        </td>
    </tr>

    <tr>
        <td height="56">
            <span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Color :</span>
        </td>
        <td>
            <select id="datas">
                <option>Red</option>
                <option>Yellow</option>
                <option>Blue</option>
                <option>Red</option>
            </select>
        </td>
        <td>

        </td>
    </tr>

    <tr>
        <td>
            <span style="font-size:18px;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#603;">Greeting :</span>
        </td>
        <td>
            <textarea type="text" name="message" id="msg" style="height:40px; width:350px;" ></textarea>
        </td>
        <td>
            <input type="submit" value="Send" id="one" style="color:#CCC; background-color:#603; border:none; width:80px; height:40px;"
            onclick="sendRequestViaMultiFriendSelector(); return false;"></span>
        </td>
    </tr>
    </table>
    </div>      

    <script>
      FB.init({
        appId  : 'XXXXXX',
        status : true,
        cookie : true,
        frictionlessRequests: true,
        oauth: true
      });


      function sendRequestViaMultiFriendSelector() {

        FB.ui({method: 'apprequests',
          message: $("#msg").val(),
          data: $("#datas").val(),

        },function getMultipleRequests(requestIds) {
            FB.api('', {"ids": requestIds }, function(response) {
            console.log(response);
             });
        }, requestCallback);
      }  

      function requestCallback(response) {
        // Handle callback here
        //var requestID = FB.api("/requestID", callback);   
        alert("Post was published.");
      }
    </script>

    <div id="fb">

    </div>
    <?php }?>
    </div>
    </body>
    </html>
于 2012-05-17T09:07:12.217 回答