Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Twitter API 1.1显示个人资料照片_Ios_Objective C_Json_Api_Twitter - Fatal编程技术网

Ios 使用Twitter API 1.1显示个人资料照片

Ios 使用Twitter API 1.1显示个人资料照片,ios,objective-c,json,api,twitter,Ios,Objective C,Json,Api,Twitter,我们正在使用iOS7推特客户端。我很少使用Twitter API,我所做的是在1.1之前 有人能帮我们把个人资料照片加载到我们的应用程序的时间表上吗 我们的代码如下 这是我们的.h文件: #import <UIKit/UIKit.h> #import <Accounts/Accounts.h> #import <Social/Social.h> #import <Twitter/Twitter.h> @in

我们正在使用iOS7推特客户端。我很少使用Twitter API,我所做的是在1.1之前

有人能帮我们把个人资料照片加载到我们的应用程序的时间表上吗

我们的代码如下

这是我们的.h文件:

    #import <UIKit/UIKit.h>
    #import <Accounts/Accounts.h>
    #import <Social/Social.h>
    #import <Twitter/Twitter.h>

    @interface FirstViewController : UIViewController <UITableViewDataSource ,                 UITableViewDelegate> {
        UIRefreshControl *myRefreshControl;
    }

    @property (nonatomic) IBOutlet UITableView *timelineTableView;
    @property (nonatomic) NSArray *timelineArray;

    @end
响应:

将返回主页订阅源。它包含一个
用户
键,您必须通过
profile\u image\u url
访问该键并获取配置文件图像


处理字典数组中的响应将解决您的问题,并且每个字典都有
用户
键,其中包含
配置文件(profile)图像(url)

您对api的调用引用的是版本1。我建议在上查看信息并检查回复格式

您可以向下搜索响应以找到“用户”对象,并从中获取配置文件图像。

请更详细地说明您面临的问题。怎么了?
    @interface FirstViewController ()

    @end

    @implementation FirstViewController

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        [self getTimeline];
        myRefreshControl = [[UIRefreshControl alloc]init];
        myRefreshControl.tintColor = [UIColor blackColor];
        [myRefreshControl setAttributedTitle:[[NSAttributedString         alloc]initWithString:@"Pull to Refresh"]];
        [myRefreshControl addTarget:self action:@selector(refreshTimeline) forControlEvents: UIControlEventValueChanged];
        [self.timelineTableView addSubview:myRefreshControl];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    -(void)getTimeline
    {
        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];

                     NSURL *requestURL = [NSURL         URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];

                     NSMutableDictionary *parameters =
                     [[NSMutableDictionary alloc] init];
                     [parameters setObject:@"200" forKey:@"count"];
                     [parameters setObject:@"1" forKey:@"include_entities"];

                     SLRequest *postRequest = [SLRequest
                                               requestForServiceType:SLServiceTypeTwitter
                                               requestMethod:SLRequestMethodGET
                                               URL:requestURL parameters:parameters];

                     postRequest.account = twitterAccount;

                     [postRequest performRequestWithHandler:
                      ^(NSData *responseData, NSHTTPURLResponse
                        *urlResponse, NSError *error)
                      {
                          self.timelineArray = [NSJSONSerialization
                                                JSONObjectWithData:responseData
                                                options:NSJSONReadingMutableLeaves
                                                error:&error];

                          if (self.timelineArray.count != 0) {
                              dispatch_async(dispatch_get_main_queue(), ^{
                                  [self.timelineTableView reloadData];
                              });
                          }
                      }];
                 }
             } else {
             }
         }];
    }

    -(void)refreshTimeline
    {
        [self getTimeline];
        [self.timelineTableView reloadData];
    }

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [self.timelineArray count];
    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle         reuseIdentifier:CellIdentifier];
        }
        NSDictionary *tweet = self.timelineArray[[indexPath row]];
        cell.textLabel.text = [[tweet objectForKey:@"user"]objectForKey:@"name"];
        cell.detailTextLabel.text = [tweet objectForKey:@"text"];
        cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:        [[tweet objectForKey:@"user"]objectForKey:@"profile_image_url"]]];

    return cell;

    }
    @end