【问题标题】:How to autoshare on facebook and twitter in ios 6?如何在 ios 6 的 facebook 和 twitter 上自动分享?
【发布时间】:2013-03-11 00:43:45
【问题描述】:

我在我的应用程序中使用 facebook 和 twitter 共享,在这里我想共享默认链接和文本而不显示共享窗口,我尝试了很多方法但仍然没有得到解决方案。

这是我的代码:

 NSString *str_face=[NSString stringWithFormat:@"Another insta from Dealnabit just claimed now, Got yours now"];
 SLComposeViewController *facebookPostVC =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook ];

[facebookPostVC addImage:[UIImage imageNamed:@"Default.png"]];

[facebookPostVC setInitialText:str_face];

[self presentViewController:facebookPostVC animated:YES completion:Nil];`

【问题讨论】:

    标签: iphone facebook twitter share


    【解决方案1】:

    1.对于 Facebook 使用 Accounts Framework 和 SLRequest 的 Social Framework 没有对话

    -(void)Post
    {
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    
    ACAccountType *facebookAccountType = [self.accountStore 
        accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    
    // Specify App ID and permissions
    NSDictionary *options = @{
          ACFacebookAppIdKey: @"my app id",
          ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"],
          ACFacebookAudeinceKey: ACFacebookAudienceFriends
    };
    
    [accountStore requestAccessToAccountsWithType:facebookAccountType 
          options:options completion:^(BOOL granted, NSError *e) {
            if (granted) {
                NSArray *accounts = [self.accountStore 
                        accountsWithAccountType:facebookAccountType];
                facebookAccount = [accounts lastObject];
            }
            else
            {
                // Handle Failure
            }
    }];
    
    NSDictionary *parameters = @{@"message": @"test post"};
    
    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
    
    SLRequest *feedRequest = [SLRequest 
            requestForServiceType:SLServiceTypeFacebook
            requestMethod:SLRequestMethodPOST 
            URL:feedURL 
            parameters:parameters];
    
        feedRequest.account = self.facebookAccount;
    
        [feedRequest performRequestWithHandler:^(NSData *responseData, 
               NSHTTPURLResponse *urlResponse, NSError *error)
        {
            // Handle response
        }];
    }
    
    1. Twitter 发布 iOS6 没有对话

        -(void)PostToTwitter
        {
      
       ACAccountStore *account = [[ACAccountStore alloc] init];
       ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:   
      ACAccountTypeIdentifierTwitter];
      
      [account requestAccessToAccountsWithType:accountType options:nil 
             completion:^(BOOL granted, NSError *error)
        {
       if (granted == YES)
       {
            NSArray *arrayOfAccounts = [account 
                   accountsWithAccountType:accountType];
      
            if ([arrayOfAccounts count] > 0)
            {
              ACAccount *twitterAccount = [arrayOfAccounts lastObject];
      
              NSDictionary *message = @{@"status": @”Test Twitter post from iOS 6”};
      
              NSURL *requestURL = [NSURL 
               URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
      
              SLRequest *postRequest = [SLRequest 
                  requestForServiceType:SLServiceTypeTwitter
                         requestMethod:SLRequestMethodPOST
                         URL:requestURL parameters:message];
            }
       }];
        }
         }
      

    【讨论】:

    【解决方案2】:

    我认为 Twitter 示例帖子缺少执行请求:

     // Post the request
     [postRequest setAccount:twitterAccount];
    
     // Block handler to manage the response
     [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
          {
           NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
          }];
    

    我会使用最新版本的 API 和 https:

    NSURL *requestURL = [NSURLURLWithString:@"https://api.twitter.com/1.1/statuses/update.json"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 2013-03-13
      • 1970-01-01
      相关资源
      最近更新 更多