当用户离线时如何发布到用户朋友墙

发布于 2024-12-20 05:20:38 字数 1428 浏览 2 评论 0原文

在我的应用程序中,用户授予我的应用程序扩展权限,我获取访问令牌并将其存储为长期访问令牌。

该用户会看到他们的朋友列表,然后他们选择一个。

我将他们的名字和 fbuid 存储在我的数据库中。

现在,在未来的某一天,我想向这位朋友的留言墙发送一条消息。 这可能吗? 如果不是,当初始用户离线时,还有哪些其他选项可以向 Facebook 中的好友发送链接?

* 更新 我能够使用长期访问令牌和离线访问来做到这一点,如下所示:

access_token = "AAACvmqy1nYoBAAZCk*************dZAMjsLxKxR7DaZBE0NxY8ZBGBW1q2mzsB9TDT0RvgeQcDdnyFJNAYRf0icnhlbikZD"
    appID        = '19307***********'
    message      = "Happy Birthday   from  your friends."
    name         = "Click here for your Birthday Surprise"
    redirect_uri = URI.parse('http://localhost:3000/facebook/')
    link         = "https://www.facebook.com/dialog/oauth?client_id=#{appID}&redirect_uri=#{redirect_uri}"
    caption      = "Your friends have created a surprise for you. Click the link to see what it is."
    picture      = 'http://www.birthdaywall.net/logo-mail.png'
    userID       = '100002*********'
    uri = URI.parse("https://graph.facebook.com/#{userID}/feed")
    req = Net::HTTP::Post.new(uri.path)
    result = req.set_form_data({:access_token => access_token , :message => message, :app_id => appID, :name => name, :link => link, :caption => caption, :picture => picture,  })
    sock = Net::HTTP.new(uri.host, 443)
    sock.use_ssl = true
    sock.start do |http|
      response = http.request(req)
    end 

我不知道这是否是最好的方法,但它对我有用,所以我正在使用它。如果有人有更好的方法,我会很高兴知道。

In my app a user grants my application extended permission and I get the access token and store it as its a long lived access token.

This user is shown a list of their friends and they select one.

I store their name and fbuid in my database.

Now on a day in the future I want to send a message to this friend's wall.
Is this possible?
If not what other options are there to send a link to the friend in Facebook when the initial user is offline?

* Update
I was able to do this with the long lived access token and offline access as follows:

access_token = "AAACvmqy1nYoBAAZCk*************dZAMjsLxKxR7DaZBE0NxY8ZBGBW1q2mzsB9TDT0RvgeQcDdnyFJNAYRf0icnhlbikZD"
    appID        = '19307***********'
    message      = "Happy Birthday   from  your friends."
    name         = "Click here for your Birthday Surprise"
    redirect_uri = URI.parse('http://localhost:3000/facebook/')
    link         = "https://www.facebook.com/dialog/oauth?client_id=#{appID}&redirect_uri=#{redirect_uri}"
    caption      = "Your friends have created a surprise for you. Click the link to see what it is."
    picture      = 'http://www.birthdaywall.net/logo-mail.png'
    userID       = '100002*********'
    uri = URI.parse("https://graph.facebook.com/#{userID}/feed")
    req = Net::HTTP::Post.new(uri.path)
    result = req.set_form_data({:access_token => access_token , :message => message, :app_id => appID, :name => name, :link => link, :caption => caption, :picture => picture,  })
    sock = Net::HTTP.new(uri.host, 443)
    sock.use_ssl = true
    sock.start do |http|
      response = http.request(req)
    end 

I don't know if this is the best way but it works for me so I am using it. If anyone has a better way I would be very happy to know about it.

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

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

发布评论

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

评论(1

情绪 2024-12-27 05:20:38

我猜你已经拥有publish_stream权限了。您还需要 offline_access 扩展权限以使您的访问令牌长期有效:

使您的应用能够随时代表用户执行授权请求。默认情况下,大多数访问令牌会在短时间内过期,以确保应用程序仅在用户主动使用应用程序时代表用户发出请求。此权限使我们的 OAuth 端点返回的访问令牌长期有效。

请参阅此处:https://developers.facebook.com/docs/reference/api/permissions/

I guess you have the publish_stream permission already. You also need the offline_access extended permission to make your access token live long:

Enables your app to perform authorized requests on behalf of the user at any time. By default, most access tokens expire after a short time period to ensure applications only make requests on behalf of the user when they are actively using the application. This permission makes the access token returned by our OAuth endpoint long-lived.

See here: https://developers.facebook.com/docs/reference/api/permissions/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文