Facebook iOS SDK 3.0,实现像一个url的动作? [英] Facebook iOS SDK 3.0, implement like action on a url?

查看:138
本文介绍了Facebook iOS SDK 3.0,实现像一个url的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Facebook iOS SDK 3.0通过Facebook open-graph-api来实现。
除了FbGraphObject之外,一切似乎都工作,因为我不知道应该如何看,因为这显然不起作用。

I'm trying to implement Like via the facebook open-graph-api with the Facebook iOS SDK 3.0. Everything seems to work except the FbGraphObject and that's because I have no idea how it should look because this clearly does not work.

我正在尝试做一个像一个对象一样的url。一个简单的喜欢通过开放图表。

What I'm trying to do is to like a url posted as an object. A simple Like with via the open-graph.

我得到以下代码的错误消息是:

The error message I get the the code below is:

The action you're trying to publish is invalid because it does not specify any 
reference objects. At least one of the following properties must be specified: object.

我使用的代码是这样的:

The code I use is this:

    FBGraphObject *objectToLike = [[FBGraphObject alloc]initWithContentsOfURL:[NSURL URLWithString:facebookLike.titleLabel.text]];

    FBRequest *requestLike = [[FBRequest alloc]initForPostWithSession:[FBSession activeSession] graphPath:@"me/og.likes" graphObject:objectToLike];

    FBRequestConnection *connection = [[FBRequestConnection alloc] init];
    [connection addRequest:requestLike
         completionHandler:
     ^(FBRequestConnection *connection, id result, NSError *error) {
         if (!error &&
             result) {

             DLog(@"NothingWentWrong");
         }

         DLog(@"MajorError: %@", error);

     }
     ];

    [connection start];






更新:


UPDATE:

检查了一些更多的信息,我猜想使用这种方法:
https://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBGraphObject/#//api/name/graphObject

Checked some more info and my guess it to use this method: https://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBGraphObject/#//api/name/graphObject

以某种方式创建一个对象。这是我可能需要做的事情的graphObject方法。任何帮助都将不胜感激。

To somehow create an object. It's the graphObject method that I probably need to do something with. Any help at all would be appreciated.

推荐答案

我实际上设法创建一个简单而且很脏的解决方案。
解决方案似乎不是最理想的,但目前是一个有效的解决方案。

I've actually manage to create a simple and quite dirty solution of this. The solution does not seem optimal but it's currently a working solution.

如果有人在这个网址上的Facebook上使用了资源管理器工具:
< a href =https://developers.facebook.com/tools/explorer/ =nofollow> https://developers.facebook.com/tools/explorer/

If anybody has used the explorer tool on facebook on this url: https://developers.facebook.com/tools/explorer/

你知道如何在Facebook上分享一个类似的URL。它必须具有URL和访问令牌。
所以我的解决方案只是为了忽略从Facebook SDK发送任何东西,只需将发送请求发送到我在浏览器工具中使用的相同URL。

You know how the URL will look like when facebook is sharing a like. It has to have the URL and an access-token. So my solution became just to disregard sending anything from the Facebook SDK and just send a post request to the same URL that I've used in the explorer tool.

如果您仔细观察,深入了解Facebook的文档,似乎有一些引用它,但是没有人明确说明如何实际连接,所以这是我的解决方案:

There seems to be some referencing to it on the facebooks docs if you look closely and deep, but no one explains exactly how to actually make the connection, so this is my solution:

NSString *urlToLikeFor = facebookLike.titleLabel.text;

NSString *theWholeUrl = [NSString stringWithFormat:@"https://graph.facebook.com/me/og.likes?object=%@&access_token=%@", urlToLikeFor, FBSession.activeSession.accessToken];
NSLog(@"TheWholeUrl: %@", theWholeUrl);

NSURL *facebookUrl = [NSURL URLWithString:theWholeUrl];

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:facebookUrl];
[req setHTTPMethod:@"POST"];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[responseData bytes]];

NSLog(@"responseData: %@", content);

如果你看看代码,我只需要url,并在url中放置两个动态字符串,一个与对象网址和一个访问令牌。我创建一个URLRequest并使其成为一个POST请求,并且从facebook获取的响应被记录下来,所以实际上可以看到是否通过。

If you look at the code I just take the url and puts two dynamic strings in the url, one with the object-url and one with the access token. I create a URLRequest and make it a POST request, and the response from facebook gets logged so one actually can see if the like go through or not.

可能有一些性能改进可以根据实际的要求完成,但如果您看到任何减速,我会将其留给您。

There might be some performance improvements that can be done with the actual requests but I will leave it up to you if you see any slowdowns.

我仍然对其他解决方案感兴趣,但这是我现在将使用的那个。

I'm still interested in other solutions but this is the one I will use for now.

这篇关于Facebook iOS SDK 3.0,实现像一个url的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆