简体   繁体   English

如何在通知一些朋友的情况下在我的Facebook墙上发布?

[英]How to Post on my Facebook Wall With notifying some friends?

My requirement is I need to post on my Facebook wall through my application with privacy setting (notifying particular friends) how to achieve this I have followed the following code 我的要求是我需要通过隐私设置(通知特定的朋友)通过我的应用程序在我的Facebook墙上发布如何实现此目标,我已遵循以下代码

-(void)sendNotification

{

    CoreDataManager *coremanagerobj = [[CoreDataManager alloc]init];
    NSArray *useridarray = [coremanagerobj GetAllMembersList]; 
    NSMutableArray *arraylist = [[NSMutableArray alloc]init]; // it will have the selected friends id
    NSMutableDictionary  *dict = [[NSMutableDictionary alloc]init];

    for (NSManagedObject *obj in useridarray)
    {
        [ arraylist addObject:[obj valueForKey:@"memberId"]];
    }

    [dict setValue:@"CUSTOM" forKey:@"value"];
    [dict setValue:arraylist forKey:@"allow"];

    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
                                                       options:NSJSONWritingPrettyPrinted 
                                                         error:&error];
    NSString *jsonString;
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"sending notification", @"message",@"Posted via testApp", @"description",jsonData ,@"privacy",
                                   nil];

    // Make the request
    if ([FBSession.activeSession isOpen])
    {
        [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                           defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:YES
                                         completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
         {
             if (!error && status == FBSessionStateOpen)
             {
                 [FBRequestConnection startWithGraphPath:@"/me/feed"
                                              parameters:params
                                              HTTPMethod:@"POST"
                                       completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                  {
                      if (!error)
                      {
                          // Link posted successfully to Facebook
                          NSLog(@"Result: %@", result);
                      }
                  }];

             }
         }];

    }
}

the Post is not getting posted in FaceBook. 该帖子未在FaceBook中发布。
I tried to debug using Breakpoint . 我尝试使用Breakpoint进行调试。
It is showing "error 它显示“错误

NSError *domain: @"com.facebook.sdk" - code: 5  0x000000010958d110"

If any one knows the solution kindly please help me Thanks in advance... 如果有人知道解决方案,请帮助我。

I changed the code like this its working for me! 我更改了这样的代码,它对我有用!

   CoreDataManager *coremanagerobj = [[CoreDataManager alloc]init];
        NSArray *useridarray = [coremanagerobj GetAllMembersList];
        NSString *stringlist = [[NSString alloc]init];
        NSMutableDictionary  *dict = [[NSMutableDictionary alloc]init];

    for (int i=0;i<useridarray.count;i++)
    {
        NSManagedObject *obj = [useridarray objectAtIndex:i];
        NSString *value = [obj valueForKey:@"memberId"];

        if (i==[useridarray count]-1) {
            stringlist = [ stringlist stringByAppendingString:[NSString stringWithFormat:@"%@",value]];
        }
        else
        {
            stringlist =  [ stringlist stringByAppendingString:[NSString stringWithFormat:@"%@,",value]];
        }
    }

[dict setValue:@"CUSTOM" forKey:@"value"];
    [dict setValue: stringlist forKey:@"allow"];

    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    NSString *jsonString;
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"sending notification", @"message",@"Posted via testApp", @"description", jsonString,@"privacy",
                                   nil];

    // Make the request
    if ([FBSession.activeSession isOpen])
    {
        [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                           defaultAudience:FBSessionDefaultAudienceFriends
                                              allowLoginUI:YES
                                         completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
         {
             if (!error && status == FBSessionStateOpen)
             {
                 [FBRequestConnection startWithGraphPath:@"/me/feed"
                                              parameters:params
                                              HTTPMethod:@"POST"
                                       completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                  {
                      if (!error)
                      {
                          // Link posted successfully to Facebook
                          NSLog(@"Result: %@", result);
                      }
                  }];

             }
         }];

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM