I am using quickblox in my app
I am trying to retrieve a dialog with certain user IDs
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:#"occupants_ids" forKey:#[#([[[DataManager sharedCenter]chat_user]ID]), #(self.opponent.ID)]];
[QBChat dialogsWithExtendedRequest:dict delegate:self];
and the result is this:
2014-08-09 13:47:02.843 App New[8752:8e0b] Performing async request:
GET https://api.quickblox.com/chat/Dialog.xml
headers:{
"QB-SDK" = "iOS 1.9.1";
"Qb-Token" = verylongtokencensored;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
(
1434093,
1367118
) = "occupants_ids";
}
2014-08-09 13:47:02.848 App New[8752:8e0b] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=0, private, must-revalidate";
Connection = "keep-alive";
"Content-Type" = "application/xml; charset=utf-8";
Date = "Sat, 09 Aug 2014 10:47:02 GMT";
Etag = "\"0c1aa29ff51b425a9be969d4fbb487a1\"";
"QB-Token-ExpirationDate" = "2014-08-09 12:47:02 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "201 Created";
"Transfer-Encoding" = Identity;
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 2330d50ea8c08851cafd30ea4c1a1c6b;
"X-Runtime" = "0.022278";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
<?xml version="1.0" encoding="UTF-8"?>
<session>
<_id>53e5fc26535c12a2f700aa3c</_id>
<application-id type="integer">10910</application-id>
<created-at type="datetime">2014-08-09T10:47:02Z</created-at>
<device-id type="integer">0</device-id>
<nonce type="integer">399</nonce>
<token>verylongtokencensored</token>
<ts type="integer">1407581207</ts>
<updated-at type="datetime">2014-08-09T10:47:02Z</updated-at>
<user-id type="integer">1434093</user-id>
<id type="integer">54616</id>
</session>
error:
2014-08-09 13:47:02.852 App New[8752:60b] received result:QBDialogsPagedResult,success:0,status:0
2014-08-09 13:47:02.852 App New[8752:8e0b] Request finished, response:
headers:(null)
body:
error:
2014-08-09 13:47:02.853 App New[8752:60b] Errors=(
"Connection closed due to timeout. Please check your internet connection."
)
How do i fix this error ?
Other requests sent to the api, which is not /chat/Dialog.xml they work fine, no connection timeout error
The right way is to use filter all:
[dict setObject:#"33,55" forKey:#"occupants_ids[all]"];
this will found all the dialogs where occupants_ids = "33,55"
you also can use filter in:
[dict setObject:#"33" forKey:#"occupants_ids[in]"];
this will return all the dialogs where occupants_ids contains 33
my bad my request had setObject forKey turned around, it should have been
[dict setObject:#[#([[[DataManager sharedCenter]chat_user]ID]), #(self.opponent.ID)] forKey:#"occupants_ids" ];
Related
When application is failed to login/authenticate successfully with restkit in first attempts due to wrong username or password, application never get success even with correct username and password, any help would be appreciated in this.
On login button i create the restkit instance and pass the information here is the code
func sendLoginRequest(userName:String,password:String){
let authenticate:String = String(format: "%#:%#", userName, password)
let plainData = (authenticate as NSString).dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
print(base64String)
headers = ["Authorization" : String(format: "Basic %#", base64String)]
self.webInterface = DFWebInterface.shareWebInterface(DFModel.sharedInstance.bMockServer)
self.webInterface?.sendRequest(nil,request: LOGIN.rawValue, nil,headers: headers as! [NSObject : AnyObject])
}
then initialize my web interface class
-(id)init:(NSString*)strURL :(BOOL)mockServer{
if(nil!=(sDFWebInterface=[super init])){
NSURL *baseURL = [NSURL URLWithString:strURL];
DFAFHTTPClient* client=[[DFAFHTTPClient alloc] initWithBaseURL:baseURL];
sDFWebInterface->rkobjmanagerDF = [[RKObjectManager alloc] initWithHTTPClient:client];
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:#"text/plain"];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
}
return sDFWebInterface;
}
After initializing i create mapping and send post request
Everything works fine if application send correct credential very first time
Here is the log for second time fail even application passing correct credential
2016-02-11 12:07:44.242 MyProject[7033:94063] I restkit.network:RKObjectRequestOperation.m:150 POST 'https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate'
2016-02-11 12:07:45.215 MyProject[7033:95645] E restkit.network:RKObjectRequestOperation.m:551 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 401" UserInfo={NSLocalizedRecoverySuggestion={"timestamp":"2016-02-11T06:37:45.103+0000","status":401,"error":"Unauthorized","message":"Failed authenticating with username and password","path":"/api/v1/authenticate"}, NSErrorFailingURLKey=https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate, AFNetworkingOperationFailingURLRequestErrorKey= { URL: https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate }, AFNetworkingOperationFailingURLResponseErrorKey= { URL: https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate } { status code: 401, headers {
"Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
"Content-Length" = 171;
"Content-Type" = "application/json;charset=UTF-8";
Date = "Thu, 11 Feb 2016 06:37:44 GMT";
Expires = 0;
Pragma = "no-cache";
Server = "";
"Set-Cookie" = "VCAP_ID=7487ff5a5d1940b895d0459b91eaec009a55f1ebd2774084b28fc6d24cab0f01; Path=/; HttpOnly";
"Strict-Transport-Security" = "max-age=31536000 ; includeSubDomains";
"Www-Authenticate" = "Basic realm=\"DEEPFIELD\"";
"X-Application-Context" = "gateway-dev:dev,cloud:0";
"X-Cf-Requestid" = "b0f1e586-8b60-4413-646d-515dbbe1f097, 954fd628-3beb-4777-41be-4eb50221b808";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = DENY;
"X-Xss-Protection" = "1; mode=block";
} }, NSLocalizedDescription=Expected status code in (200), got 401}
2016-02-11 12:07:45.216 DeepField[7033:95645] E restkit.network:RKObjectRequestOperation.m:215 POST 'https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate' (401 Unauthorized / 0 objects) [request=0.9732s mapping=0.0000s total=0.9869s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 401" UserInfo={NSLocalizedRecoverySuggestion={"timestamp":"2016-02-11T06:37:45.103+0000","status":401,"error":"Unauthorized","message":"Failed authenticating with username and password","path":"/api/v1/authenticate"}, NSErrorFailingURLKey=https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate, AFNetworkingOperationFailingURLRequestErrorKey= { URL: https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate }, AFNetworkingOperationFailingURLResponseErrorKey= { URL: https://myproject-dev.apps.mycompany-iot-cloud.com/api/v1/authenticate } { status code: 401, headers {
"Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
"Content-Length" = 171;
"Content-Type" = "application/json;charset=UTF-8";
Date = "Thu, 11 Feb 2016 06:37:44 GMT";
Expires = 0;
Pragma = "no-cache";
Server = "";
"Set-Cookie" = "VCAP_ID=7487ff5a5d1940b895d0459b91eaec009a55f1ebd2774084b28fc6d24cab0f01; Path=/; HttpOnly";
"Strict-Transport-Security" = "max-age=31536000 ; includeSubDomains";
"Www-Authenticate" = "Basic realm=\"myproject\"";
"X-Application-Context" = "gateway-dev:dev,cloud:0";
"X-Cf-Requestid" = "b0f1e586-8b60-4413-646d-515dbbe1f097, 954fd628-3beb-4777-41be-4eb50221b808";
"X-Content-Type-Options" = nosniff;
"X-Frame-Options" = DENY;
"X-Xss-Protection" = "1; mode=block";
} }, NSLocalizedDescription=Expected status code in (200), got 401}
2016-02-11 12:07:45.216 DeepField[7033:94063] Error from server in Post Request
I just set header again for restkit httpclient and it starts working.
RKObjectManager* rkobjmanagerDF;
[[rkobjmanager.HTTPClient defaultHeaders] setValue:#"application/json" forKey:#"Content-Type"];
[[rkobjmanagerDF.HTTPClient defaultHeaders] setValue:#"application/json" forKey:#"Accept"];
I have one issue facebook signing with quickblox api.
After getting AccessToken by using FBSDK.
[QBRequest logInWithSocialProvider:#"facebook" accessToken:accessToken accessTokenSecret:nil successBlock:^(QBResponse *response, QBUUser *user) {
} errorBlock:^(QBResponse *response) {}
i think facebook returns correct token string.
CAAVS4qDIQb4BAMS7pTl3P1EmtW1ZCOOpbTCQFWrBI8QsA7ufOTYapjF3rEpW1ojZChgOZB7mj6AWDocDSdtxFbksqP3FyZCIou6bUC6ON4ZCRFGPes6TBzufh68A9fBSSz6baTYCZCTIyZAoDhYdBZAvrHF3609cAiEZCesnWrtqYleqPv7YHIadrWf2x1oWItypF3V3pbDgsHd7MSSCcZBvK4yuHGeCUvf7qMPFznuRZCfwNCOcQBDU8ynHnzDPpnnhLEZD
[logInWithSocialProvider: accessToken: ...] function returns following error
[QBResponse], status: 422
2015-12-09 14:27:27.049 NudgeBuddies[2598:124844] [QBCore] Response error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: client error (422)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7ffde266ce40> { URL: https://api.quickblox.com/login.json } { status code: 422, headers {
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Length" = 47;
"Content-Type" = "application/json; charset=utf-8";
Date = "Wed, 09 Dec 2015 06:27:26 GMT";
"QB-Token-ExpirationDate" = "2015-12-09 08:27:26 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.6.2";
Status = "422 Unprocessable Entity";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = ab3443c24c0d5ee0a18d796eaf996cb7;
"X-Runtime" = "0.221723";
"X-UA-Compatible" = "IE=Edge,chrome=1";
} }, NSErrorFailingURLKey=https://api.quickblox.com/login.json, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a7b22 62617365 223a5b22 4c6f6769 6e206f72 20656d61 696c2072 65717569 72656422 5d7d7d>, NSLocalizedDescription=Request failed: client error (422)}
Please Help me.
How can i solve this problem?
Regards.
In QuickBlox SDK 2.6.5 we have improved stability and we have enabled detail logging so you are able to see the reasons why problem happens.
QuickBlox has open source project Q-municate with Facebook login and you can check it by yourself.
Thanks!
I am having a weird issue when I try to delete a content item (picture blob item for the user), stored as PNG picture file in the back-end database.
The delete proceeds without errors, but gives "422 Unprocessable Entity". What does this mean? The status of the content item seems to be OK and ready when checked in Quickblox admin panel.
I have uploaded the content with following API call:
[QBContent TUploadFile:imageData fileName:#"profile.png" contentType:#"image/png" isPublic:YES delegate:self];
I am trying to delete the object with following API call:
[QBContent deleteBlobWithID:blobID delegate:self];
QB logs:
Performing async request:
DELETE http://api.quickblox.com/blobs/91049.xml
headers:{
"QB-SDK" = "iOS 1.8";
"Qb-Token" = b9e3d1cc708c8444070544df8c642ad194509e67;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:
2013-12-12 14:33:52.328 QBTestApp[21095:6b73] Request finished, response:
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Length" = 49;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 12 Dec 2013 13:33:58 GMT";
"QB-Token-ExpirationDate" = "2013-12-12 15:32:22 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "422 Unprocessable Entity";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 3f235134e5aa0bd012ef78e54cddc164;
"X-Runtime" = "0.039680";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:
error:
<?xml version="1.0" encoding="UTF-8"?>
<errors/>
Any ideas what I might be doing wrong here? Thanks (again) in advance! :-)
The feeling that you are trying to delete a blob file that does not exisе. Please make sure that you are trying to delete a blob file after the upload and the creation process is completed(calling completedWithResult: with successful result).
If I could see the order of method calls TUploadFile: and deleteBlobWithID: in the code, I could help you more quickly.
i am using QuickBlox Simple Chat for how to know how it was working.
In demo ex.2 user first is USER1 and Other is USER2.
After some time USER1 message display in table where the side of USER2 message and USER2 message is display in side of USER1 messages.
Get a response to the server like this
Request finished, response:
RestResponse:
------
<QBASIHTTPRequest: 0xa288c00>
headers:{
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-cache";
Connection = Close;
"Content-Length" = 106;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Sat, 05 Oct 2013 05:54:05 GMT";
"QB-Token-ExpirationDate" = "2013-10-05 07:53:46 UTC";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "422 Unprocessable Entity";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = c70e07ac0a8571253773cde59c23676c;
"X-Runtime" = "0.223264";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>No one can receive the message</error>
</errors>
error:
I am writing a simple application on iOS and I am trying to consume a RESTFull webservice
To have some tips and get some knowledge I first start with twitter without using ios integrated libs, but I always get stocked on Auth.
Any working sample or link will be appreciated, as reminder twitter is not my final goal
For instance this is one of my code, based on RestKit and AFOAuth1Client :
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
AFOAuth1Client * twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:url key:kCLIENTID secret:kCLIENTSECRET];
[twitterClient authorizeUsingOAuthWithRequestTokenPath:#"oauth/request_token"
userAuthorizationPath:#"oauth/authorize"
callbackURL:[NSURL URLWithString:#"af-twitter://success"]
accessTokenPath:#"oauth/access_token"
accessMethod:#"POST"
scope:#""
success:^(AFOAuth1Token *token, id responseObject) {
}
failure:^(NSError *error) {
}];
as you can see it does not work :
2013-06-17 16:59:01.389 restKitTest[14490:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-06-17 16:59:02.653 restKitTest[14490:c07] I restkit.network:RKObjectRequestOperation.m:174 POST 'http://api.twitter.com/oauth/request_token'
2013-06-17 16:59:03.051 restKitTest[14490:c07] E restkit.network:RKObjectRequestOperation.m:203 POST 'http://api.twitter.com/oauth/request_token' (401 Unauthorized) [0.3980 s]: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x9c96640 {NSLocalizedRecoverySuggestion=Failed to validate oauth signature and token, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x9877e20> { URL: http://api.twitter.com/oauth/request_token }, NSErrorFailingURLKey=http://api.twitter.com/oauth/request_token, NSLocalizedDescription=Expected status code in (200-299), got 401, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x9aac910> { URL: http://api.twitter.com/oauth/request_token } { status code: 401, headers {
"Cache-Control" = "no-cache, no-store, must-revalidate, pre-check=0, post-check=0";
"Content-Encoding" = gzip;
"Content-Length" = 62;
"Content-Type" = "text/html; charset=utf-8";
Date = "Mon, 17 Jun 2013 14:59:03 GMT";
Expires = "Tue, 31 Mar 1981 05:00:00 GMT";
"Last-Modified" = "Mon, 17 Jun 2013 14:59:03 GMT";
Pragma = "no-cache";
Server = tfe;
"Set-Cookie" = "_twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCOJ3pVI%252FAToHaWQiJTIyYzUxN2UwNmUwYTI4%250AYzU1NmU0OTYxZDA5MDcwMmI3IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--3291687666d367b6ccddc74513532bf56ea144d9; domain=.twitter.com; path=/; HttpOnly, guest_id=v1%3A137148114312677519; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 14:59:03 UTC";
Status = "401 Unauthorized";
Vary = "Accept-Encoding";
"x-frame-options" = SAMEORIGIN;
"x-mid" = af106773611449e1226d5dd5d531b64d91e4f3f8;
"x-runtime" = "0.01153";
"x-transaction" = 24e58d8eb3b7cdb5;
"x-ua-compatible" = "IE=10,chrome=1";
"x-xss-protection" = "1; mode=block";
} }}
"401 Unauthorized" indicates that your credentials are incorrect. So check your API keys.
try this:
[twitterClient authorizeUsingOAuthWithRequestTokenPath:#"/oauth/request_token"
userAuthorizationPath:#"/oauth/authorize"
callbackURL:[NSURL URLWithString:#"instantshare-twitter://success"]
accessTokenPath:#"/oauth/access_token"
accessMethod:#"POST"
scope:nil
success:^(AFOAuth1Token *accessToken, id responseObject) {
[twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
} failure:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
Note the line scope:nil, for some reason it doesn't work with empty string.
Among other things, check your application settings in twitter. I'm not sure if this is the case, but I enabled Allow this application to be used to Sign in with Twitter and set Callback URL to some random valid url