iOS: Twitter update profile api giving error - ios

I am trying to access update profile api of twitter. But its giving error.
let conn = WebserviceConnectionManager(serviceTokenId: "Twitter profile")
let url = NSURL(string: "https://api.twitter.com/1.1/account/update_profile.json")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
let oAuthToken = FHSTwitterEngine.sharedEngine().accessToken.key
let oAuthTokenSecret = FHSTwitterEngine.sharedEngine().accessToken.secret
request.addValue(oAuthToken, forHTTPHeaderField:"oauth_token")
request.addValue(oAuthTokenSecret, forHTTPHeaderField:"oauth_token_secret")
conn.delegate = self
conn.startConnection(request)
Callback method gives me following error:
errors = (
{
code = 215;
message = "Bad Authentication data.";
}
);
Any help would be highly appreciated.

Since Twitter's API 1.1 does not allow access without authentication, because you have to use access tokens and secret keys; all requests must be made with a server-side script.
follow steps here and you will fixed your problem.

Related

How to resolve iOS SSO Auth failure with 1000 code?

I am going to implement SSO Auth to our enterprise application. I watched this WWDC talk. There is not enough information. I tried to use a simple code from this talk like this:
let url = URL(string: "realm://{{identity_server_url}")! //I checked this by changing realm: to https:.
let ssoProvider = ASAuthorizationSingleSignOnProvider(identityProvider: url)
let request = ssoProvider.createRequest()
request.requestedOperation = .operationLogin
let authController = ASAuthorizationController(authorizationRequests: [request])
authController.delegate = self
authController.presentationContextProvider = self
authController.performRequests()
self.ssoProvider = ssoProvider
self.authController = authController
But this is always failed with this error description:
Error Domain=com.apple.AuthenticationServices.AuthorizationError Code=1000 "(null)"

Apple Music API getting 403 'Forbidden' when trying to fetch recent tracks

Hey there people of the great world!
I am attempting to retrieve all the recent tracks from the Apple Music API using the following HTTP request:
static let AMRecentTracks = "https://api.music.apple.com/v1/me/recent/played/tracks"
Shamefully I keep receiving an error 403 forbidden. This makes no sense as I am able to successfully do a search request using this:
static let AMMusicURL = "https://api.music.apple.com/v1/catalog/"
Any help would be greatly appreciated. It seems there is little information about this specific case. I've checked.
I am making the request with a Bearer and a token.
static let prefix = "Bearer "
to it I am appending the developer token.
Below is my code:
func fetchRecentPlayedResources(_ complition: #escaping (Result<[Song], Error>)->Void) {
let suffix = "?types=songs"
guard let searchURL = URL(string: Request.AMRecentTracks + suffix) else { return }
var musicRequest = URLRequest(url: searchURL)
musicRequest.httpMethod = HTTPRequest.GET
musicRequest.addValue(HTTPRequest.prefix + self.developerToken, forHTTPHeaderField: HTTPRequest.authorization)
URLSession.shared.dataTask(with: musicRequest) { [weak self] (data, response, error) in
guard let self = self else { return }
if let error = error {
complition(.failure(error))
} else {
if let data = data {
self.parseSongs(with: data) { songs in
complition(.success(songs))
}
}
}
}.resume()
}
You need to add two tokens when sending personalised requests, the example from the iTunes API documentation shows this:
curl -v -H 'Music-User-Token: [music user token]' -H 'Authorization: Bearer [developer token]' "https://api.music.apple.com/v1/catalog/us/songs/203709340"
So maybe just adding the developer token as Authorisation isn't enough and this is why you are getting a 403 error. Again, as the documentation states - this is due to invalid or insufficient authorisation.

Could not load module: CTLS

I import JWT(using .Package(url:"https ://github.com/vapor/jwt.git", majorVersion: 1))
enter image description here
The project can build and run. But when I look into CTLS, the Xcode shows "Could not load module: CTLS". I don't know why.
At the same time, the JWT I create seems not right. Here is my codes:
import JWT
import Vapor
get("token") { req in
let algValue = StructuredData.string("ES256")
let kidValue = StructuredData.string("CapExedKid")
let headerData = StructuredData.object(["alg":algValue,"kid":kidValue])
let header = JSON.init(headerData)
let issValue = StructuredData.string("CapExdTeam")
let sec = Int(Date().timeIntervalSince1970)
let iatValue = StructuredData.number(StructuredData.Number(sec))
let expValue = StructuredData.number(StructuredData.Number(sec+1000000))
let claimsData = StructuredData.object(["iss":issValue,"iat":iatValue,"exp":expValue])
let claims = JSON.init(claimsData)
let url = URL.init(fileURLWithPath: "/Users/aamac/Desktop/HelloWorld/AuthKey_demoKey.p8")
let data = try Data.init(contentsOf: url)
let signer = ES256.init(key: data.makeBytes())
let jwt = try JWT.init(headers: header, payload: claims, signer: signer)
let token = try jwt.createToken()
return token }
I use the token to do the authenticate requests as Apple Music API says, I got a http status code 500..
I enter this in terminal:
curl -v -H 'Authorization: Bearer [developer token]' "https ://api.music.apple.com/v1/catalog/us/songs/203709340"
and got 500..
But I use a Python library to get the token and do the request in terminal, it works, so I doubt that the JWT in swift have some kind of problem...Can anyone tell me??
I experienced a similar problem (https://github.com/vapor/jwt/issues/47). What worked for me was using data.bytes.base64Decoded instead of data.makeBytes() when initializing the signer.

How do I do Wishlist Member authentication into a WordPress site from a non PHP application?

I'm having problems when trying to do Wishlist Member authentication from an iOS Swift application. The goal is to retrieve the current users email address. I’ve tried to interpret this info: http://codex.wishlistproducts.com/tutorial-authenticating-with-the-wishlist-member-api-from-a-non-php-application-ios-android-netetc/, but keep getting "success" :0, "ERROR_CODE" :65537, "ERROR" : "Access denied - Invalid authentication”. First step works, i.e. I’m able to get the “lock” cookie. I’m using SwiftHash for MD5. This is what I'm doing:
1) Run auth command in order to get the “lock” cookie.
http://content.xxxxxxxx.com/?/wlmapi/2.0/json/auth
This works fine and I get a lock cookie.
2) Then I run the following request using the API key and the “lock” cookie
let lock = self.getWLMAPILock(). // retrieve lock cookie
let key = “xxxxxxxxxxxxxxxxxxxx” // key removed for security
let newString = “\(lock)\(key)” // concatenate the two strings
let newKey = MD5(newString). // create auth_key
let postString = ("key=\(newKey),support_emulation=1")
let postData = postString.data(using: String.Encoding.utf8, allowLossyConversion: true)
let request : NSMutableURLRequest = NSMutableURLRequest(url: URL(string: “http://content.xxxxxxxx.com/?/wlmapi/2.0/json/auth")!)
request.httpMethod = “POST"
request.httpBody = postData
otiWebview.loadRequest((request as NSMutableURLRequest) as URLRequest)
This generates an error: "success" :0, "ERROR_CODE" :65537, "ERROR" : "Access denied - Invalid authentication"
3) Run request with url:
http://content.xxxxxxxx.com/?/wlmapi/2.0/json/members
Not run yet.
Solved it! The above scheme is basically correct, just had to add
let newKey = MD5(newString).lowercased()

iOS facebook login without SDK http post Swift/Obj-C

Let me start off by saying the purpose of this code is so I can practice on various other sites with login pages or forms. This is why I do no wish to use Facebook's SDK. So please...
Do not point me to Facebook's SDK (many other questions specifically asking for without SDK have been given SDK answers)
Ideally I would like to create an app that has preset information that will login to a site (such as Facebook) when the app opens or a button is pressed
I'd prefer an answer in Swift but I can read Objective - C and may be able to decipher it
Here is some sample code I've tried:
let myURL = NSURL(string: "https://mobile.facebook.com")
let request = NSMutableURLRequest(URL: myURL!)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-type")
let postString = "email=*email&pass=*pass&login=Log In"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let postInt = postString.characters.count
request.setValue("\(postInt)", forHTTPHeaderField: "Content-length")
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)")
}
if let HTTPResponse = response as? NSHTTPURLResponse {
let sCode = HTTPResponse.statusCode
if sCode == 200 {
// Then do something.
self.webView.loadRequest(request)
}
}
print("respone = \(response)")
}
task.resume()
*email = The user's email
*pass = The user's password
note: email, pass, Log In were taken from the form name values on the html code.
Current results- I am able to get the email to appear on opening of the app but the password is blank and it doesn't appear to have attempted a log in.
Please help and let me know if you need any clarifications
PS I've been looking for about a week now to no avail so I apologize if the answer is somewhere. I am not completely familiar with terminology to look for it.

Resources