【问题标题】:Posting to Facebook friends wall instead of sending a notification with iOS发布到 Facebook 朋友墙而不是使用 iOS 发送通知
【发布时间】:2012-07-23 19:53:03
【问题描述】:

我目前有以下代码,可以选择一个随机的 Facebook 朋友并将帖子发布到他们的墙上。我希望能够从所有朋友中选择(而不是随机选择一个)并发布到他们的墙上。如果有人可以帮助我编写以下代码,那就太好了:)

 case gkAPIFriendsForDialogFeed:
            {
                NSArray *resultData = [result objectForKey: @"data"];
                // Check that the user has friends
                if ([resultData count] > 0) {
                    // Pick a random friend to post the feed to
                    int randomNumber = arc4random() % [resultData count];
                    [self apiDialogFeedFriend: 
                     [[resultData objectAtIndex: randomNumber] objectForKey: @"id"]];
                } else {
                    [self showMessage:@"You do not have any friends to post to."];
                }
                break;
            }

此代码选择所有朋友,但不会发布到他们的墙上,而是向他们发送通知:

case gkAPIGetAppUsersFriendsUsing:
        {
            NSMutableArray *friendsWithApp = [[NSMutableArray alloc] initWithCapacity:1];
            // Many results
            if ([result isKindOfClass:[NSArray class]]) {
                [friendsWithApp addObjectsFromArray:result];
            } else if ([result isKindOfClass:[NSDecimalNumber class]]) {
                [friendsWithApp addObject: [result stringValue]];
            }

            if ([friendsWithApp count] > 0) {
                [self apiDialogRequestsSendToUsers:friendsWithApp];
            } else {
                [self showMessage:@"None of your friends are using Whatto."];
            }

            [friendsWithApp release];
            break;
        }

【问题讨论】:

    标签: iphone ios facebook facebook-graph-api


    【解决方案1】:

    在多个用户的墙上发帖违反 Facebook 平台条款。您应该坚持使用 Requests 方法,因为这是向多个用户发送消息的正确方法。

    【讨论】:

    • 我只需要选择一位朋友并发布到他们的墙上。一次没有多少朋友。只需从所有朋友中选择一个,然后发布到他们的墙上。代码的第一部分执行此操作,但它显示了一个随机朋友。我希望能够从列表中选择一个朋友——就像我在上面发布的第二个代码块中所做的那样。谢谢:)
    • 在这种情况下,您需要构建一个视图来加载好友列表并让用户选择要发布到的好友。
    • 我已经有了。唯一的问题是它只是发送通知而不是墙上的帖子。这就是我需要弄清楚的。
    【解决方案2】:

    获取随机id后调用该函数

    并根据您的应用更改参数。

    -(void)sendFBPost:(UIButton *)tag

    {

    NSString *Message = [NSString stringWithFormat:@"-posted via iPhone App"];
    NSMutableDictionary *params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    Message, @"message", nil];
    NSString *post=[[appDelegate.FBFriendListArray objectAtIndex:tag.tag] objectForKey:@"id"];
    
    [[appDelegate facebook] requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",post] andParams:params1 andHttpMethod:@"POST" andDelegate:self];
    
    UIAlertView  *alert = [[UIAlertView alloc] initWithTitle:@"Message!" message:@"Invitation Send Sucessfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
    

    }

    【讨论】:

    • 有没有办法改变它,而不是选择一个随机的朋友,它显示所有?谢谢
    • 我会为 ObjectAtIndex 的 tag.tag 添加什么内容?我需要用户能够从朋友列表中选择一个朋友。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多