创建 Facebook 应用程序请求

发布于 2024-12-27 03:49:29 字数 427 浏览 4 评论 0原文

我试图在特定事件发生时从应用程序向用户发送消息。现在我有这段代码

$param = array(
   'message'      => 'XYZ shared a file with you',
   'data'         => 'additiona_string_data',
   'access_token' => $facebook->getAccessToken(),
);
$tmp = $facebook->api("/$uid/apprequests", "POST", $param);

,但我总是得到 Uncaught OAuthException: (#2) Failed to create any app request returned

我不知道问题出在哪里。

I'm trying to send a message from an app to a user when a specific event happens. Right now I have this code

$param = array(
   'message'      => 'XYZ shared a file with you',
   'data'         => 'additiona_string_data',
   'access_token' => $facebook->getAccessToken(),
);
$tmp = $facebook->api("/$uid/apprequests", "POST", $param);

but I always get Uncaught OAuthException: (#2) Failed to create any app request thrown

I don't know where is the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云淡风轻 2025-01-03 03:49:29

您应该阅读请求文档。
其中有关于两种不同类型的请求的解释。

您需要的是 应用生成的请求,这意味着您需要应用访问令牌而不是用户。

我假设您正在使用用户访问令牌,因为您没有在代码示例中包含 facebook 对象的启动,并且可能已经验证了用户,因此 getAccessToken() 调用将返回用户访问令牌而不是应用程序访问令牌。

You should read the requests documentation.
In there is an explination about two different types of requests.

What you need is the app generated requests, that means you'll need the apps access token and not the users.

I assume that you are using the users access token because you did not include the initiation of the facebook object in your code sample and have probably verified the user already hence the getAccessToken() call will return the users access token and not the applications access token.

弄潮 2025-01-03 03:49:29

我对“当特定事件发生时,我试图从应用程序向用户发送消息。现在我有这个代码”的意思有点困惑。

  1. 当有人在用户墙上发帖时向用户发送电子邮件

  2. 向用户发送活动邀请

    向用户

  3. 向用户发送应用邀请

  4. 当发生“XYZ 与您共享文件”等情况时在用户墙上书写。

要回答

  1. 您需要用户的电子邮件read_stream权限。使用实时更新监控他的墙,然后使用您的服务器 SMTP 向他发送电子邮件。

  2. 请参阅http://developers.facebook.com/docs/reference/ api/event/#invited 了解如何创建活动邀请

  3. 正如 @Lix 指出的,请参阅https://developers.facebook.com/docs/channels/#requests

  4. 您应该使用新的开放图对象/操作来完成此操作。请参阅此示例: https://developers.facebook.com/docs/beta/opengraph/教程/

I'm a little confused as to "I'm trying to send a message from an app to a user when a specific event happens. Right now I have this code" means.

  1. Sending an email to a user when someone posts on their wall

  2. Sending an event invite to a user

  3. Sending an app invite to a user

  4. Writing on a users wall when something happens like 'XYZ shared a file with you'.

To answer

  1. You need email and read_stream permissions of the user. Monitor his wall using the RealTime Updates and then email him using your server SMTP.

  2. See http://developers.facebook.com/docs/reference/api/event/#invited on how to create an event invite

  3. As @Lix pointed out, see https://developers.facebook.com/docs/channels/#requests

  4. You should accomplish this using the new Open Graph object/actions. See this example: https://developers.facebook.com/docs/beta/opengraph/tutorial/

半衬遮猫 2025-01-03 03:49:29

您可以通过以下方式接收 Facebook 应用程序访问令牌:

https://graph.facebook.com/oauth/access_token?client_id=FB_APP_ID&client_secret=FB_APP_SECRET&grant_type=client_credentials

使用 Facebook PHP SDK 发布应用程序到用户请求的工作代码示例(根据需要添加错误处理):

$facebook = new Facebook(array(
  'appId'  => FB_APP_ID,
  'secret' => FB_APP_SECRET,
));

$token_url = "https://graph.facebook.com/oauth/access_token?" ."client_id=" . 
   FB_APP_ID ."&client_secret=" . FB_APP_SECRET ."&grant_type=client_credentials";

$result = file_get_contents($token_url);
$splt = explode('=', $result);
$app_access_token =$splt[1];

$facebook->setAccessToken($app_access_token);

$args = array(
    'message' => 'MESSAGE_TEXT',

);
$result = $facebook->api('/USER_ID/apprequests','POST', $args);

You can receive Facebook app access token via:

https://graph.facebook.com/oauth/access_token?client_id=FB_APP_ID&client_secret=FB_APP_SECRET&grant_type=client_credentials

Working code sample to post app-to-user request using Facebook PHP SDK (add error handling where required):

$facebook = new Facebook(array(
  'appId'  => FB_APP_ID,
  'secret' => FB_APP_SECRET,
));

$token_url = "https://graph.facebook.com/oauth/access_token?" ."client_id=" . 
   FB_APP_ID ."&client_secret=" . FB_APP_SECRET ."&grant_type=client_credentials";

$result = file_get_contents($token_url);
$splt = explode('=', $result);
$app_access_token =$splt[1];

$facebook->setAccessToken($app_access_token);

$args = array(
    'message' => 'MESSAGE_TEXT',

);
$result = $facebook->api('/USER_ID/apprequests','POST', $args);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文