1

私は自分のアプリケーションで 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];`
4

2 に答える 2

7

1.アカウントフレームワークとソーシャルフレームワークのSLRequestを対話なしで使用するFacebookの場合

-(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];
          }
     }];
      }
       }
    
于 2013-03-21T13:37:02.530 に答える
1

リクエストを実行するには、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"];
于 2014-02-15T20:15:28.773 に答える