简体   繁体   English

Facebook access_token请求返回NOTHING

[英]facebook access_token request return NOTHING

it's been 5 days that I'm stuck in the implementation of a simple fb login and I'm banging my head like a motherf***r. 已经有5天了,我被困在一个简单的fb登录的实现中,我像母亲一样敲着脑袋。 anyways. 无论如何。

I'm at the point that I'm trying to set the accessToken by hand. 我正要手动设置accessToken。 like shown in this post. 就像这篇文章中所示。

https://github.com/facebook/php-sdk/issues/418#issuecomment-2605012 https://github.com/facebook/php-sdk/issues/418#issuecomment-2605012

the only problem is that the oauth/access_token call returns nothing and I'm guessing that it's a pretty messed up behaviour. 唯一的问题是,oauth / access_token调用什么也不返回,我猜这是一个非常混乱的行为。 this is the snippet I use to make the call 这是我用来拨打电话的代码段

                $token_url = "https://graph.facebook.com/oauth/access_token?client_id=".FB_APPID."&redirect_uri=".urlencode($curUrl)."&client_secret=".FB_APPSECRET."&code=".$_GET['code'];
                log_to_file("curPageURL: ".$token_url);
                $response = file_get_contents($token_url);
                log_to_file("resp: ".$respone);

the log_to_file is a custm method that logs the taken message in a file so that I can have the log situation in a tail -f scenario. log_to_file是一个custm方法,将已接收的消息记录在文件中,这样我就可以在tail -f场景中查看日志情况。

what happens here is that the log "resp: ". 这里发生的是日志“ resp:”。 returns nothing at all. 完全不返回任何内容。

did anyone face the same problem? 有人遇到过同样的问题吗?

thx in advance. 提前。 this thing is driving me insane. 这件事使我发疯。

and I can officially state that the fb sdk is the most buggy and worse-documented service I've ever used. 我可以正式声明fb sdk是我使用过的最多错误且记录最差的服务。

Facebook has the most badly-documented API in the world. Facebook拥有世界上记录最烂的API。 I remember the time I used it and couldn't help swearing all the time ! 我记得我曾经用过的时间,不禁一直发誓! :) Here is a piece of pseudo-code that did work for me. :)这是一段对我有用的伪代码。 It gains permission from a user to post a link on his wall. 它获得了用户的许可,可以在其墙上张贴链接。 I'm just posting it so that maybe you can take some hints and make your code work: 我只是在发布它,以便您可以获取一些提示并使代码正常工作:

<?php

//A function for cURL operations.
function callFb($url)
{
            $ch = curl_init();
            curl_setopt_array($ch, array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true
            ));

            $result = curl_exec($ch);
            curl_close($ch);
            return $result;
}

$url = "https://graph.facebook.com/oauth/access_token?client_id=<your_client_id>&redirect_uri=".urlencode("<the_url_where_the_user_is_redirected_after_granting_permission>")."&client_secret=<your_client_secret>";

/* Get access token. */
$access_token = callFb($url);

/* Parse the result to get access token */
$access_token = substr($access_token, strpos($access_token, "=")+1, strlen($access_token));

/* Save access token, if you want to for future.*/
mysql_query("INSERT INTO fb_auth_tokens (id,auth_token) VALUES('$_GET[id]','$auth_token')");

/* Post to users wall */

$apprequest_url = "https://graph.facebook.com/me/feed";
$mymessage="Hello World !";
$parameters = "?access_token=" . $access_token . "&message=" .
urlencode($mymessage) .
        "&link=".urlencode("<link_that_you_want_to_post>").
        "&description=<description_of_the_link>".
        "&method=post";
$myurl = $apprequest_url . $parameters;
$result = callFb($myurl);

// Thy shall be done. :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM