直接发布在用户墙上 HTTP/1.0 400
我使用 facebook 指南制作 facebook 应用程序
当用户允许应用程序访问时,索引页面将其重定向到 tst.php,直接发布在用户墙上
我在 index.php 中使用以下代码:
index.php
<?php
require_once 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'app_id',
'secret' => 'app_secret',
'cookie' => true,
));
$app_id = app_id;
$canvas_page = 'http://apps.facebook.com/tstsample/tst.php';
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" .
$app_id . "&redirect_uri=" . urlencode($canvas_page) .
"&scope=email offline_access publish_stream";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
以及下面是我在 tst.php 中使用的代码,用于直接在用户墙上发布:
tst.php
<?php
$feedurl = "https://graph.facebook.com/134875956586326";
$ogurl = "http://www.facebook.com/apps/application.php?id=134875956586326";
$app_id = “134875956586326”;
$app_secret = "app_secret";
$mymessage = urlencode("Hello World!");
$access_token_url = "https://graph.facebook.com/oauth/access_token";
$parameters = "type=client_credentials&client_id=" .
$app_id . "&client_secret=" . $app_secret;
$access_token = file_get_contents($access_token_url .
"?" . $parameters);
$apprequest_url = "https://graph.facebook.com/feed";
$parameters = "?" . $access_token . "&message=" .
$mymessage . "&id=" . $ogurl . "&method=post";
$myurl = $apprequest_url . $parameters;
$result = file_get_contents($myurl);
echo "post_id" . $result;
?>
在我运行应用程序后,出现两个错误,
- 我看到访问允许页面,而不是在索引页面上停止
- 按照我在上面的代码中提到的手动继续 tst.php 后,我收到 PHP 错误
以下是错误:
Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?type=client_credentials&client_id=�134875956586326�&client_secret=606636c88cd434c5140986d8472fc639)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad Request in /home5/onkhuras/public_html/escribir/tstsample/tst.php
on line 14
Warning: file_get_contents(https://graph.facebook.com/feed?&message=Hello+World%21&id=http://www.facebook.com/apps/application.php?id=134875956586326&method=post)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad Request in /home5/onkhuras/public_html/escribir/tstsample/tst.php
on line 21
post_id
如何解决这两个错误?
注意:我从 Facebook 获取这两个代码,并在 index.php 和 txt.php 中使用
I make facebook application using facebook guide
When user allow application access than the index page redirect it to tst.php which directly post on user wall
I use the below code in index.php:
index.php
<?php
require_once 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'app_id',
'secret' => 'app_secret',
'cookie' => true,
));
$app_id = app_id;
$canvas_page = 'http://apps.facebook.com/tstsample/tst.php';
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" .
$app_id . "&redirect_uri=" . urlencode($canvas_page) .
"&scope=email offline_access publish_stream";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
And below is the code which I use in tst.php which use to directly post on user wall:
tst.php
<?php
$feedurl = "https://graph.facebook.com/134875956586326";
$ogurl = "http://www.facebook.com/apps/application.php?id=134875956586326";
$app_id = “134875956586326”;
$app_secret = "app_secret";
$mymessage = urlencode("Hello World!");
$access_token_url = "https://graph.facebook.com/oauth/access_token";
$parameters = "type=client_credentials&client_id=" .
$app_id . "&client_secret=" . $app_secret;
$access_token = file_get_contents($access_token_url .
"?" . $parameters);
$apprequest_url = "https://graph.facebook.com/feed";
$parameters = "?" . $access_token . "&message=" .
$mymessage . "&id=" . $ogurl . "&method=post";
$myurl = $apprequest_url . $parameters;
$result = file_get_contents($myurl);
echo "post_id" . $result;
?>
And after i run the application two errors occur
- I see the access allow page than it stops on index page
- After manually going on the tst.php as I mentioned in the above code, I receive PHP errors
Below are the errors:
Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?type=client_credentials&client_id=�134875956586326�&client_secret=606636c88cd434c5140986d8472fc639)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad Request in /home5/onkhuras/public_html/escribir/tstsample/tst.php
on line 14
Warning: file_get_contents(https://graph.facebook.com/feed?&message=Hello+World%21&id=http://www.facebook.com/apps/application.php?id=134875956586326&method=post)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad Request in /home5/onkhuras/public_html/escribir/tstsample/tst.php
on line 21
post_id
How do I resolve these two errors?
Note: I get these two codes from Facebook which I use in index.php and txt.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
再次检查身份验证指南 - https://developers.facebook.com/docs/authentication/ 。
您需要 /dialog/oauth 返回的代码才能从 https://graph.facebook.com/ 获取 access_token oauth/access_token
Check the authentication guide again - https://developers.facebook.com/docs/authentication/.
You need the code returned by /dialog/oauth to get an access_token from https://graph.facebook.com/oauth/access_token
我遇到了类似的问题(第二条错误消息),并通过使用 $ogurl 的应用程序 ID 解决了这个问题(tst.php 文件中的最后几行):
在我的情况下,这导致将消息发布到应用程序墙。
I had a similar problem (the second error message) and got it resolved by using my app id for $ogurl like this (the last few lines in your tst.php file):
In my case that lead to posting the message to the app wall.