2011-08-01 36 views
1

我想用Open Graph API复制Facebook动作链接。我有下面的代码片段:Facebook图形API和动作链接

HTTParty.post("https://graph.facebook.com/me/feed", query: { message: "...", picture: "...", access_token: "...", actions: [{ link: "http://google.com", name: "Example" }] }) 

但是它返回(我不知道为什么):

{"error":{"type":"OAuthException","message":"(#100) The post's action links must be valid URLs."}} 

任何人有使用图形API操作链接的经验吗?

+0

也许尝试URL编码?或者出于某种原因将www从“http://google.com”中删除可能会导致问题 – DSchultz

+0

@DSchultz试图添加“www”(没有运气)。我如何对其进行网址编码? –

+0

url_encoded_string = CGI :: escape(“http://www.google.com”) – DSchultz

回答

5

请注意,actions数组应该是JSON编码,HTTParty可能不会自动/正确地执行此操作。尝试

HTTParty.post(
    "https://graph.facebook.com/me/feed", 
    :query => { 
     :message => "...", 
     :picture => "...", 
     :access_token => "...", 
     :actions => [{ link: "http://google.com", name: "Example" }].to_json 
    } 
) 

(假设你有一个库包括提供阵列#to_json ...)

+0

谢谢!这是问题。 –