I'm trying to send a gmail message in Swift using the GoogleAPIClientForREST and GTMOAuth2 libraries but I'm getting the aforementioned error.
Here's my code:
let message = GTLRGmail_Message()
message.raw = "test"
let query = GTLRGmailQuery_UsersMessagesSend.query(withObject: message, userId: "example#gmail.com", uploadParameters: nil)
let gmailService = GTLRGmailService()
let auth = GTMOAuth2Authentication()
auth.clientID = gmailClientID
gmailService.authorizer = auth
gmailService.executeQuery(query) { ticket, object, error in
print(ticket)
print(object)
print(error)
}
and here's the error:
Optional(Error Domain=com.google.GTMOAuth2 Code=-1001 "(null)" UserInfo={request=<NSMutableURLRequest: 0x600000016ed0> { URL: https://www.googleapis.com/gmail/v1/users/example%40gmail.com/messages/send?prettyPrint=false }})
Notes:
I used "example#gmail.com" for sake of asking the question, I'm using a real email in my app.
I followed all the basic steps in Google's tutorial
Make sure that you've integrated GTMOAuth2 properly into your app by following this tutorial. Be sure to register the Platform as Other and NOT iOS otherwise you'll get "invalid_client" error when authenticating.
You may also check the given solution on this thread.
Related
In my iOS app I'm trying to use the Facebook Swift SDK so that a user can post a URL to a specific Facebook page that they manage.
I've managed to get the following code working - but it only shares the post to my home timeline:
let content = LinkShareContent(url: URL(string: urlString)!)
let sharer = GraphSharer(content: content)
sharer.failsOnInvalidData = true
sharer.completion = {
(result) in
print(result)
}
do {
try sharer.share()
}
catch (let error) {
print(error.localizedDescription)
}
I believe that I need to use the graphNode property to specify the destination page and that the correct format is as follows:
sharer.graphNode = "/\(pageId)"
However, when I set this property before posting, I am getting an error:
failed(Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
I've tried a dozen different formats to specify the node but they all return the same error and I can't find any working examples.
I managed to resolved this issue. It turns out that the graphNode path above is correct but I was looking in the wrong place due to the error message I was getting. Instead I just needed to specify the accessToken parameter.
graphSharer.accesstoken = myPageAccessToken
Note: The access token is not the user's current access token, but an access token you can retrieve when calling the /me/accounts API.
var graphPath = "/me/accounts"
I also then had an issue posting to the page because I had only requested the publish_actions permission. From the documentation, this appears to be suitable but it only worked where I requested further permissions as follows:
loginManager.logIn(withPublishPermissions: ["publish_actions",
"manage_pages", "publish_pages"], ...
Hopefully this will be of use to someone in future. :-)
Building and ios chat application. Started testing generated a token but when it is passed as customtoken ios throwing error.
FIRAuth.auth()?.signIn(withCustomToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyeHAiOjE0ODM4NzEyOTAsInYiOjAsImQiOnsidWlkIjoiNTg0MTVhM2ZkOTA1MGVjZjAzOGI0NWU3In0sImlhdCI6MTQ4MTI3OTI5MH0.QIxFmbap_cDsUB5L_OxE29haev7cSe29lHZtmVTnJ3c") { (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.signedIn(user!)
}
The custom token format is incorrect. Please check the documentation.
where as when i test the same token online its working fine.
http://jsfiddle.net/firebase/XDXu5/
Any help will be very helpfull.
I'm trying to use the AWS SDK to create an endpoint on an application so that I can send push notifications. The push notifications go through when I manually enter the details on the AWS console but I'm trying to register the device from inside the app so that new users can be signed up.
Following the steps on http://docs.aws.amazon.com/mobile/sdkforios/developerguide/setup.html I have created the credentials for the app in the AppDelegate and use these credentials in another class.
The code I'm using to try and access the AWS SNS is :
func subscribeEndpoint(json: JSON)
{
let sns = AWSSNS.defaultSNS()
let request = AWSSNSCreatePlatformEndpointInput()
let user_id = json["id"].string!
request.token = "XXXXX"
request.customUserData = user_id
print("token : \(token) user : \(user_id)")
request.platformApplicationArn = "XXXX"
sns.createPlatformEndpoint(request).continueWithBlock({ (task: AWSTask!) -> AnyObject! in
if task.error != nil {
print("Error dis: \(task.error!)")
} else {
let createEndpointResponse = task.result as! AWSSNSCreateEndpointResponse
print("endpointArn: \(createEndpointResponse.endpointArn)")
}
return nil
})
}
I have tested using the device token generated by the device when registering for notifications (this value works when inputting on the AWS SNS console). The user_id has also been tested and isn't null.
The error I keep getting is
Error dis: Error Domain=com.amazonaws.AWSSNSErrorDomain Code=0 "(null)"
Not really sure what the cause of the problem is but if anyone could help me it would be greatly appreciated. Thanks
This is most likely an authorization error. Are you setting the default service configuration correctly?
When you use AWSSNS.defaultSNS() it loads the configuration from the default configuration object. The credential provider used for the default configuration should assume a role which has permissions to call createPlatformEndpoint from the client.
You can verify it from the IAM console if the role that is assumed has enough permissions.
Thanks,
Rohan
I'm trying to use Google places API to get autocomplete.
I've checked everything:
API keys are activated (disabled every restriction)
I'm calling GMSServices.provideAPIKey and GMSPlacesClient.provideAPIKey
Initializing the object placesClient = GMSPlacesClient.shared()
The call I'm making is:
let filter = GMSAutocompleteFilter()
filter.type = .establishment
placesClient?.autocompleteQuery(textField.text!, bounds: nil, filter: filter) { (predictionList, error) in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let list = predictionList{
self.resultList = list
}
}
The error I'm getting is:
Printing description of error: Error
Domain=com.google.places.ErrorDomain Code=-3 "An internal error
occurred in the Places API library. If you believe this error
represents a bug, please file a report using the instructions on our
community and support page
(https://developers.google.com/places/support)."
UserInfo={NSLocalizedFailureReason=An internal error occurred in the
Places API library. If you believe this error represents a bug, please
file a report using the instructions on our community and support page
(https://developers.google.com/places/support).,
NSUnderlyingError=0x608000445370 {Error
Domain=com.google.places.server.ErrorDomain Code=-1 "(null)"
UserInfo={NSUnderlyingError=0x60800024f030 {Error
Domain=com.google.GTLRErrorObjectDomain Code=400 "(Bad Request)"
UserInfo={error=Bad Request, GTLRStructuredError=GMSx_GTLRErrorObject
0x60800024f9f0: {message:"Bad Request" errors:[1] code:400},
NSLocalizedFailureReason=(Bad Request)}}}}}
Has anyone else seen this problem in Xcode 8 iOS 10? Thanks
EDIT: Now it seems that some requests are working... Maybe the server is having problems?
I'm running Xcode beta 10, with ios 10 beta, and I got my facebook login working.
if I simply just add
import Firebase and FIRApp.configure() in my appdelegate, I get the following error:
Optional(Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = CIheVvb2bpQ;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}})
This makes virtually no sense to me, I'm not doing anything with firebase yet, not trying to authenticate or track a login, why would simply importing firebase, and configuring it in the appdelegate cause this, and any ideas on how to fix?