使用AFIncrementalStore与验证令牌 [英] Using AFIncrementalStore with an Auth token

查看:252
本文介绍了使用AFIncrementalStore与验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在iOS客户端上 App.net ,我想使用<一个HREF =htt​​ps://github.com/AFNetworking/AFIncrementalStore相对=nofollow> AFIncrementalStore 与我的应用程序核心数据实现同步的Web服务。

我已经得到了两到对于不需要身份验证令牌API请求工作,但我无法弄清楚如何使用身份验证令牌与AFIncrementalStore。

在换句话说,我能够拉下全球饲料,因为它不要求身份验证:

https://alpha-api.app.net/stream/ 0 /职位/流/全球

...但是,要获得用户的视频流,需要AUTH(你会注意到这个链接给出一个错误):

https://alpha-api.app.net/stream/0 /职位/流

据我了解,我需要一个的auth_token 追加到API调用结束,但我不知道怎么做,使用AFIncrementalStore。

更新:这里的code的,目前使用的是全局流块:

这是一个方法,直接计入AFIncrementalStore 的例如App.net项目拉动。

   - (*的NSURLRequest)requestForFetchRequest:(NSFetchRequest *)fetchRequest withContext:(*的NSManagedObjectContext){背景
    NSMutableURLRequest * mutableURLRequest =零;
    如果([fetchRequest.entityName isEqualToString:@邮报]){
        mutableURLRequest = [自我requestWithMethod:@GET路径:@流/ 0 /职位/流/全球性参数:无];
    }    返回mutableURLRequest;
}


所有你有这样做上述改变它正确使用一个访问令牌是添加参数的要求,而不是通过零。

要建立的参数只是使一个的NSDictionary 通过键和值需要。例如,在我的一些App.net code我有这个

 的NSDictionary * PARAMS = @ {@的access_token:令牌};

使用新的编译器指令这构建了一个的NSDictionary 用一个键(在这种情况下,'ACCESS_TOKEN')与价值的的NSString 标记。

在你有这样只是让你的要求是这样的:

  [自requestWithMethod:@GET路径:@流/ 0 /职位/流参数:PARAMS];

要传递请求参数。

让我知道,如果这还不够清楚!

I'm working on an iOS client for App.net, and I'd like to use AFIncrementalStore to sync the web service with my Core Data implementation in the app.

I've gotten the two to work for API requests that don't require an auth token, but I can't figure out how to use the auth token with AFIncrementalStore.

In other words, I'm able to pull down the global feed, since it doesn't require auth:

https://alpha-api.app.net/stream/0/posts/stream/global

...however, to get a user's stream, you need auth (you'll note this link gives an error):

https://alpha-api.app.net/stream/0/posts/stream

I understand that I need to append an auth_token to the end of the API call, but I'm not sure how to do that using AFIncrementalStore.

Update: Here's the chunk of code that currently gets the global stream:

This is a method pulled directly from the example App.net project included in AFIncrementalStore.

-(NSURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest withContext:(NSManagedObjectContext *)context {
    NSMutableURLRequest *mutableURLRequest = nil;
    if ([fetchRequest.entityName isEqualToString:@"Post"]) {
        mutableURLRequest = [self requestWithMethod:@"GET" path:@"stream/0/posts/stream/global" parameters:nil];
    }

    return mutableURLRequest;
}

解决方案

All you have to do with the case above to alter it to correctly use an access token is add parameters to the request instead of passing nil.

To build the parameters simply make an NSDictionary with the keys and values you need. For example in some of my App.net code I have this

NSDictionary *params = @{@"access_token": token};

Using the new compiler directives this builds an NSDictionary with a single key (in this case 'access_token') with the value in the NSString token.

After you have this just make your request something like:

[self requestWithMethod:@"GET" path:@"stream/0/posts/stream" parameters:params];

To pass the parameters in the request.

Let me know if this isn't clear enough!

这篇关于使用AFIncrementalStore与验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆