Sending data back from cloud code - ios

I use Stripe in Parse Cloud Code and receive a Stripe ID (String), but I want to send that stripe id back to Xcode. What is the best way of doing this?
I've tried to first of all send the stripe ID to Parse, and in Xcode I do a fetch...
But I think that's a bad idea because if there are multiple users processing the payments at same time, it's hard to get the right stripe ID for the user.

To return data from cloud code, take a look at this tutorial post.
Basically all you have to do is return the stripe id like this
response.success(stripeId);
Receiving data looks like this :
[PFCloud callFunctionInBackground:#"averageStars" withParameters:params block:^(NSString *stripeId, NSError *error) {
if (!error) {
// code
}
}];

Related

MSGraphSDK user details API callback not responding back when user password changed in iOS

I tried to get the user details using MSGraph SDK in iOS using below API method. Iam successfully received the user details all the time. But when user charged their password or update their credentials, i received the oauthConnection Error: only in log. And i didn't receive any call back in the below API. Why it is not responding back when any kind of error occurred? Please help me. Thanks in advance.
[MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
self.graphClient = [MSGraphClient client];
[[[self.graphClient me]request]getWithCompletion:^(MSGraphUser *response, NSError *error) {
if(!error){
// Im able to get back here
}
else{
//Im not received any call back here when user changed their password or any error occurred.
[self.authProvider disconnect];
}
}];`
I am kinda new to MS Graph, so I might be missing something, but your graphClient declaration seems a little bit poor to me.
Try to download this sample: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2
And check it's declaration of graphClient.
You might be missing the part which refreshes the token?

Where can I view my PFUser objects in the Parse Data Browser?

I'm getting to know Parse and am already having a tough problem.
I'm working with the User Login flow. I need to be able to delete the User object I've just created. Problem is, on the Dashboard, I only have the Installation data table.
I realized I wasn't explicitly saving this user object, although locally (on iOS) I could log in with the currentUser object credentials. So I thought I'd remove the install from the simulator and try again (hey, since my data wasn't on the dashboard.)
Now I tried re-installing the app, using the same username/pass, and Parse SDK is telling me these are already taken!
So the question is, where is this User, and how do I completely remove the data so I can start over again?
2015-10-15 16:37:29.999 ParseApp[21428:2003831] [Error]: username myUserName already taken (Code: 202, Version: 1.8.5)
This doesn't solve the problem, but is kind of like a workaround for testing purposes. I made a method:
- (IBAction)pressedDeleteSelf:(id)sender
{
[[PFUser currentUser] deleteInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
[PFUser logOut];
[self performSegueWithIdentifier:#"unwindSignedOut" sender:self];
}
}];
}
Which then allows me to re-create a user with the same credentials. I still have no idea why the PFUser table does not show up in the Dashboard.
Oh myyy... how silly do I feel. With all these different tutorials I've been running, apparently I had been doing all this stuff using the wrong AppID and Client Key. A rookie mistake, but hopefully someone else doesn't have to trip on this.
To be clear, solution is to make sure your App ID and Client key in the Parse dashboard match what you call in code:
// Initialize Parse.
[Parse setApplicationId:PARSE_APP_ID
clientKey:PARSE_CLIENT_KEY];
Embarrassed...

manipulating parse.com class with cloud code

I have a random messaging app using parse.com as a backend. I am saving the messages in a class called "Messages" with the keys:
"messageBody"(which is the content of the message) and
"senderId"(which is the sender id of course)
After this gets saved in my Messages class, I am using cloud code to query 3 random users and send this message to them.
My question is which is the best way to do this because I foresee errors in my current method. The current method i am using is after the user presses send I save the message to Parse.com and then I call the "send to 3 random users" cloud function, but what if my message has not been successfully saved to the parse backend before the cloud function is implemented?
-(IBAction)send{
PFObject *message = [PFObject objectWithClassName:#"Message"];
[message setObject:self.messageContent forKey:#"messageBody"];
[message setObject:[[PFUser currentUser] objectId] forKey:#"senderId"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
if(error){
//show alert with error
}
else{
//everything was successful
}
}];
[PFCloud callFunctionInBackground:#"sendToThreeRandomUsers" withParameters:#{}
block:^(NSString *result, NSError *error) {
if (!error) {
//cloud function was a success!
}
}];
}
Basically I want to know if there is a way that whenever there is a new object in the Messages class I can say send this to 3 random users from my parse backend rather than calling it from my users device?
Or Should I just totally skip saving it to my parse backend and just send it straight to my cloud code as a parameter of the cloud function? Then save it to my backend. what if the messageBody is very big though?
So this question really isnt about code but the way to structure it.
Wish I could use Hector Ramos as a tag for this question
Why don't you write a afterSave method for your Messages class. Whenever new message is saved successfully, this method (Parse.Cloud.afterSave("Messages", function(request, response) {..}) is executed and 3 random users can be selected. The API explanation is in below link;
https://parse.com/docs/cloud_code_guide#functions-onsave
Hope this helps,
Regards.

Share facebook without being able to edit text

I'm creating an game where I have a share button. In this share button I would like to share text and a link. It is important that the user can't edit the text since they would be able to change the score. What is the best solution for this? I've searched, but in most guides, you're able to change the text as a user.
What's the solution?
The short answer is that you're not supposed to post something on a user's behalf without giving them the option of editing the comment/status. You can do it with an API call (rather than a share sheet), but this should only be used to post content that the user entered elsewhere in the app.
// NOTE: pre-filling fields associated with Facebook posts,
// unless the user manually generated the content earlier in the workflow of your app,
// can be against the Platform policies: https://developers.facebook.com/policy
[FBRequestConnection startForPostStatusUpdate:#"User-generated status update."
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Status update posted successfully to Facebook
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description);
}
}];
This is from Facebook's "Sharing in iOS" documentation
Another option (though possibly also against the rules) is to create an image from the text and let the user share the image. Before doing this, however, put yourself in the user's shoes - do you really need to post something like that?

Facebook Like/Unlike gives error message

I am building an application which implements Facebook. Through this application I can like and comment on a post. I am fetching Home feeds for the logged in user. Now for Like operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: POST
Here, the POST_ID is the ID I am getting for each feed and the access token of the logged in user.
Now in most of the cases I can like the feed using this API. But some posts don't have Like Connections. How do I know which feed has a like connection & which does not.
Now coming to Unlike. For Unlike operation I am using the graph API :
https://graph.facebook.com/POST_ID/likes?&access_token=ACCESS_TOKEN
with HTTPMethod: DELETE
I can unlike some posts or feeds using this API. But for some I get an error message. In that case i am using for example:
This is the
POST_ID = 12345_67890. When I get error message for this I am using the 67890 as the POST_ID in this case & I am getting success to unlike a post/feed.
Again in using this 67890 as POST_ID gives error in some cases & in that case I am using OBJECT_ID if exists in the feed I am receiving. And I am getting true response in some cases.
But in rest of the cases I can't find any solution for Like & Unlike of a feed/post in Facebook.
Waiting for positive reply.
if you are using correct post_id of feed than it will never produce any error while liking/disliking post on facebook by following code
if do you want to like than change HTTPMethod to POST otherwise set DELETE for dislike. there is no need of accesstoken to call this api.if you are using so it will not produce any error
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/likes",#"Post_id"] parameters:nil HTTPMethod:#"DELETE" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(#"error: %#", error.localizedDescription);
}
else
{
NSLog(#"ok!! %#",result);
}
}];

Resources