Facebook-iOs-API 如何在自定义函数中获取响应

发布于 2024-12-11 21:54:26 字数 1074 浏览 0 评论 0原文

如何捕获自定义函数中的响应?基本上答案是:

- (void)request:(FBRequest *) request didReceiveResponse:(NSURLResponse *)response{
NSLog(@"I have some information");
//  [wait stopAnimating];
  //wait.hidden;
}

  - (void)request:(FBRequest *) request didLoad:(id)result{
   if ([result isKindOfClass:[NSArray class]]){
            result = [result objectAtIndex:0];
    } 
    else{
      // dictionaryWithNames = result;
         infoStatus.text = [result objectForKey:@"name"];
     infiId.text = [result objectForKey:@"id"];
}
if ([result objectForKey:@"data"]){
    arrayWithFriends = [result objectForKey:@"data"];
    if (arrayWithFriends != nil) {
    for (NSDictionary *output in arrayWithFriends){
        NSString *namaFriends = [output objectForKey:@"name"];
        NSLog(@"Your Friend %@", namaFriends);
        infoStatus.text = @"If you could see konsole... You can't";
        continue;
        } 
    } else {
        infoStatus.text = @"You Haven't Got friends or Mutuals";
    }
}

}

但是我需要另一个函数,因为在这个函数中仅使用很少的模式不可能(或太难)获得我需要的所有响应。

How to catch response in custom function? Basically answer gets:

- (void)request:(FBRequest *) request didReceiveResponse:(NSURLResponse *)response{
NSLog(@"I have some information");
//  [wait stopAnimating];
  //wait.hidden;
}

  - (void)request:(FBRequest *) request didLoad:(id)result{
   if ([result isKindOfClass:[NSArray class]]){
            result = [result objectAtIndex:0];
    } 
    else{
      // dictionaryWithNames = result;
         infoStatus.text = [result objectForKey:@"name"];
     infiId.text = [result objectForKey:@"id"];
}
if ([result objectForKey:@"data"]){
    arrayWithFriends = [result objectForKey:@"data"];
    if (arrayWithFriends != nil) {
    for (NSDictionary *output in arrayWithFriends){
        NSString *namaFriends = [output objectForKey:@"name"];
        NSLog(@"Your Friend %@", namaFriends);
        infoStatus.text = @"If you could see konsole... You can't";
        continue;
        } 
    } else {
        infoStatus.text = @"You Haven't Got friends or Mutuals";
    }
}

}

But i need to have another function because its impossible(or too hard) to get all responses that i need, using only few patterns in this function.

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

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

发布评论

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

评论(1

回眸一笑 2024-12-18 21:54:26

您可以在此处的示例应用程序中使用与 facebook 开发人员相同的架构

https://github.com/facebook/wishlist-mobile-sample/blob/master/iOS/Wishlist/Wishlist/HomeViewController.m

他们创建 currentAPIcall 变量并根据请求填充它,如下所示:

/**
* Make a Graph API Call to get information about the current logged in user.
*/
- (void) apiFQLIMe {

    currentAPICall = kAPIFQLMe;
    // Using the "pic" picture since this currently has a maximum width of 100 pixels

    // and since the minimum profile picture size is 180 pixels wide we should be able
    // to get a 100 pixel wide version of the profile picture

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:

                                   @"SELECT uid, name, pic FROM user WHERE uid=me()", @"query",

                                   nil];
    [facebook requestWithMethodName:@"fql.query"

                                     andParams:params
                                 andHttpMethod:@"POST"

                                   andDelegate:self];
}




- (void)request:(FBRequest *)request didLoad:(id)result {
    [self hideActivityIndicator];
    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }
    switch (currentAPICall) {
        case kAPIFQLMe:
        {
            // This callback can be a result of getting the user's basic
            // information or getting the user's permissions.
            if ([result objectForKey:@"name"]) {
                // If basic information callback, set the UI objects to
                // display this.
                self.profileNameLabel.text = [result objectForKey:@"name"];
                // Get the pr

...

you can use same schema as facebook developers in their sample application here

https://github.com/facebook/wishlist-mobile-sample/blob/master/iOS/Wishlist/Wishlist/HomeViewController.m

they create currentAPIcall variable and fill it depending on request like that:

/**
* Make a Graph API Call to get information about the current logged in user.
*/
- (void) apiFQLIMe {

    currentAPICall = kAPIFQLMe;
    // Using the "pic" picture since this currently has a maximum width of 100 pixels

    // and since the minimum profile picture size is 180 pixels wide we should be able
    // to get a 100 pixel wide version of the profile picture

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:

                                   @"SELECT uid, name, pic FROM user WHERE uid=me()", @"query",

                                   nil];
    [facebook requestWithMethodName:@"fql.query"

                                     andParams:params
                                 andHttpMethod:@"POST"

                                   andDelegate:self];
}




- (void)request:(FBRequest *)request didLoad:(id)result {
    [self hideActivityIndicator];
    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }
    switch (currentAPICall) {
        case kAPIFQLMe:
        {
            // This callback can be a result of getting the user's basic
            // information or getting the user's permissions.
            if ([result objectForKey:@"name"]) {
                // If basic information callback, set the UI objects to
                // display this.
                self.profileNameLabel.text = [result objectForKey:@"name"];
                // Get the pr

...

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