I have add youtube APi in my application and I have successfully authorized my account and get access token from google via auth 2.0.
but now i want to add comment on video and i am getting error as below:
1. invalide token
2. NoLinkedYouTubeAccount
etc.
i thought, i am not able to correctly use and understand Authorization: Bearer ACCESS_TOKEN
statement of google and i am confusing how to pass my token with my call.
My code is as below:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"application/atom+xml" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest addValue:[NSString stringWithFormat:#"Bearer %#",#"my token" forHTTPHeaderField:#"Authorization"];
[theRequest addValue: #"2" forHTTPHeaderField:#"GData-Version"];
[theRequest addValue: #"key=mykey" forHTTPHeaderField:#"X-GData-Key"];
[theRequest setHTTPMethod:#"POST"];
Can you help me to solve this issue and suggest me to call correct way?
Thanks
You may be trying to access with an Service account rather than an actual YouTube account.
You can check out Objective C samples from YouTube and use YouTube Objective-C client library.
Related
I have to implement the XML base soap service in my iOS application.i have goggled the things but dint find proper implementation. here is my URL of XML based WSDL service.
http://www.XXX.XX.XX/IntegrationService/MobileAppServicePort?wsdl
following is the response when we call this service in SOA Client
Service name: MobileAppIntegrationService
Description: undefined
Targetnamespace: http://integration.XXX.XXXX.XXX.XX/
Operations: (please choose one of the listed operations)
1. Operation: getNewsDetails
2. Operation: getNewsList
3. Operation: login
4. Operation: getRulesList
now can any one please tell me how can i implement this kind of web-service to post or get the data from above operations as i have never been to this XML based soap service.
we have tried following thing to use one opertaion of CreateUser
soapMessage = #"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><getCountriesList xmlns=\"http://integration.esi.dtps.gov.ae/\"></getCountriesList></soap:Body></soap:Envelope>";
//Now create a request to the URL
NSURL *url = [NSURL URLWithString:#""]; //<--
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
//ad required headers to the request
[theRequest addValue:#"" forHTTPHeaderField:#"Host"];//<--
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"" forHTTPHeaderField:#"SOAPAction"];//<--
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
and we are confused that what to add in "HOST" "SOAPACTION" & "URL". can anyone please guide.
I want to make a simple iOS application which calls a Web service.
I reffered the following link
http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Respon
I tried to run the sample project that i got from this link.But I am getting the response like
"soap:ClientServer did not recognize the value of HTTP Header SOAPAction: http://tempuri.org/."
I am not able to find out what the reason behind this error is.And I am very much new to web services.Can anyone help me to solve this error?And someone please tell me ,what are the basic steps to call a web service from an iOS application.Is there any special version requirements of Xcode and iOS for calling web services?Please help me ...Thanks in advance for any help...
This is the code that I am using for sending the request
NSString *soapMessage = [NSString stringWithFormat:#"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
" <CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\n"
"<Celsius>%#</Celsius>\n"
"</CelsiusToFahrenheit>\n"
"</soap:Body>\n"
"</soap:Envelope>\n" ,textFieldCelcisus.text];
NSURL *url = [NSURL URLWithString:#"http://w3schools.com/webservices/tempconvert.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[theRequest addValue: #"http://tempuri.org/" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [NSMutableData data] ;
NSLog(#"webdata is %#",webData);
NSLog(#"Problem");
}
else
{
NSLog(#"theConnection is NULL");
}
Change this line:
[theRequest addValue: #"http://tempuri.org/" forHTTPHeaderField:#"SOAPAction"];
into:
[theRequest addValue: #"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:#"SOAPAction"];
The server is complaining about the value for the SOAPAction. The SOAPAction's are defined in the WSDL, and are different for each operation.
Since you provided the service URL and the service is public, i just checked it.
The SOAPAction for 'CelsiusToFahrenheit' appeared to be:
http://www.w3schools.com/webservices/CelsiusToFahrenheit
Note that each operation has it's own SOAPAction, e.g.:
CelsiusToFahrenheit -> http://www.w3schools.com/webservices/CelsiusToFahrenheit
FahrenheitToCelsius -> http://www.w3schools.com/webservices/FahrenheitToCelsius
etc...
Above answer is right, only suggestion that use NSURLSession instead of NSURLConnection.
I have an iOS application which connects via OAuth 2.0 to Facebook. I would like to make a POST request which achieves the equivalent of this code in iOS:
curl -F 'access_token=...' \
-F 'message=Hello. I like this new API.' \
https://graph.facebook.com/[USER_ID]/feed
I found a nice tutorial online and I followed all the instructions, but I still can get my POST request to work. Here is my code:
NSString *post = post_text.text;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *ready_post = [NSString stringWithFormat:#"https://graph.facebook.com/1313573269/feed?message=%#&access_token=CAACEdEose0cBAHgdZAon2EZBZCzjoLkhg7jrqvZAbliuoOQ2E2Exc4rZCAxPzeVEADwnQaNLYuG16Gq6q6LLLLLLLLVQ7LZAncXCc53qE2iyzleZAPXGajsgjnBTuo6YdJCZAxVGIYYD8sZCgQ9ypZCo0iOZBNuyrechBfee2yptlK9tmgdosZA7wrKg8ZD", postData];
[request setURL:[NSURL URLWithString:ready_post]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
As you can see I am hard coding the access token for the time being just as a test. But I cant seem to get my app to actually POST anything to Facebook.
Thanks, Dan.
You're trying to post a JSON to the GraphAPI - which you can't do.
Instead of that, you have to use parameters when posting (query string or HTTP request parameters).
See: Publish to Feed.
I'm having a weird issue calling an API from my ios app. I create a post request
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:5.0];
[request setHTTPMethod:#"POST"];
I then create json to send to the request and add it to the body of the request like so:
[request setHTTPBody:encodedData];
Finally, I am adding a few cookies which I then set with:
NSArray* cookieArray = [NSArray arrayWithObjects: sessionCookie, uidCookie, vidCookie, nil];
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookieArray];
[request setAllHTTPHeaderFields:headers];
This all works fine. However, since I am sending json I'm trying to be good and also set the content type with this line of code:
[request setValue:#"application/json; charset=utf-8" forHTTPHeaderField: #"Content-Type"];
As soon as I add this line of code, the data I sent to the body of the request no longer gets passed as part of the request. Does this sound like behavior anyone else has experienced?
I am also using
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
Check this explanation
What does "Content-type: application/json; charset=utf-8" really mean?
Below is the code to request web service, I get the feed back #"List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user."
NSString *soapMessage = #"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetList xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><listName>Contact</listName></GetList></soap:Body></soap:Envelope>";
NSString * wsURL = #"http://192.168.11.133/Jason/_vti_bin/Lists.asmx";
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",wsURL]];
ASIHTTPRequest * theRequest = [ASIHTTPRequest requestWithURL:url];
[theRequest addRequestHeader:#"Content-Type" value:#"text/xml; charset=utf-8"];
[theRequest addRequestHeader:#"SOAPAction" value:#"http://schemas.microsoft.com/sharepoint/soap/GetList"];
[theRequest setUsername:#"username"];
[theRequest setPassword:#"password"];
[theRequest addRequestHeader:#"Content-Length" value:msgLength];
[theRequest setRequestMethod:#"POST"];
[theRequest appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setDefaultResponseEncoding:NSUTF8StringEncoding];
[theRequest setTimeOutSeconds:20];
[theRequest setDidFailSelector:#selector(onRequestFail:)];
[theRequest startSynchronous];
The webservice is from sharepoint.
I feel my code is correct. Can anyone give some advice? Thanks.
offtopic:
ASIHTTPRequest is not longer supported and for POST Request the is a class ASIFormDataRequest
Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)
You could you an alternative like:
AFNetworking (my favorite choice)
MKNetworkKit
This should be SharePoint issue.
Using IP directly will cause some issues.
I solve the problem by mapping the host name.