安卓:使用服务器端使用Parse工作时, [英] Android: Using server-side when working with Parse

查看:286
本文介绍了安卓:使用服务器端使用Parse工作时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的朋友正在使用的应用程序,我们希望使用Parse.com作为我们的数据的基础上,从中我们可以检索信息。 我们不能决定什么是访问上解析的数据的最佳方式。为了这个例子中,我们的应用程序。 (即客户端)需要的东西上存储的解析数据的基础上(例如一定数目) - 它应该使用解析的API直接运行查询,或者应该将其作出的请求到服务器侧,让它检索解析该号码,并其发送回客户端?

Me and my friend are working on an app., and we wish to use Parse.com as our data base from which we can retrieve info. We can't decide what is the best way to access the data on Parse. For the sake of the example, our app. (i.e. client side) needs something stored on the Parse data base (say some number) - should it directly run the query using the Parse API, or should it make a request to a server side, let it retrieve that number from Parse, and send it back to the client?

我们知道有没有明确的答案,但我们无法找到有关此特定情形的答案。我们看到这篇文章:当使用客户端或服务器端? ,  但是这不完全一样的情况下。

We know there's no definite answer, but we couldn't find answer regarding this specific situation. We read this post: When to use client-side or server-side?, but this not exactly the same case.

我坚持认为,我们应该尽量单独尽可能从客户端和数据库,并留下这些查询的人谁是负责人(服务器),那里有我的朋友宣称,这增加了不必要的复杂性,因为这是很自然的跑使用由解析提供的工具来从客户端访问数据的基础上,而不需要一个协议等

I claim that we should try to seperate as much as possible from client side and data bases, and leave these queries run by someone who's in charge (server), where my friend claims this adds unnecessary complication, since it's very natural to use the tools supplied by Parse to access the data base from the client side, without the need for a protocol etc.

我们希望并欣赏任何意见,

We'd appriciate any advice,

感谢您。

推荐答案

在一般情况下,请便并进行正常的通话

我会鼓励你这样做的第一在任何情况下,把一切工作的两端。

I'd encourage you to do that first in any case, to get everything working on both ends.

然后如果有必要转到云code。

Then if necessary go to Cloud Code.

如果您打算做的多个平台(如iOS和Android),云code可以节省大量的时间,巨大的。

If you are going to do more than one platform (ie iOS and Android), cloud code can be a huge timesaver, huge.

不要忘了简单的通话,云code是在浪费时间。 正常解析调用是惊人的,令人难以置信的,惊人的,快速迅捷的工作。

BUT don't forget that for simple calls, cloud code is a waste of time. "Normal" Parse calls are amazingly, incredibly, amazingly, fast and quick to work with.

(你们年轻人永远也不会知道有多么糟糕的事情是在旧时代。)

(You young people will never know how bad things were in the old days.)

目前是完全没有错使用正常解析电话 - 这样做,

There is utterly nothing "wrong" with using normal Parse calls - so do that.

对于这个问题,当你从字面上必须使用云code调用 - 你就会知道,因为你将不能够以普通呼叫做到这一点:)

Regarding the question, when do you literally have to use a cloud code call -- you'll know, because you won't be able to do it with a normal call :)

不要忘了,你可以简单地使用afterSave或beforeSave云code,做大量的工作非常频繁。你往往不从字面上需要去云code自定义来电。

Don't forget very often you can simply use "afterSave" or "beforeSave" in cloud code, to do a huge amount of work. You often don't literally need to go to a custom call in cloud code.

下面是一个梦幻般

如果您需要做的多一点......可能使它成为一个云code函数。如果你有做三个或三个以上的东西,那么绝对会让其云code函数。

If you have to do "more than one thing" ... probably make it a cloud code function. If you have to do "three or more things" then DEFINITELY make it a cloud code function.

这是一个很好的经验法则。

That's a good rule of thumb.

(同样,正如我说的,往往只是一个afterSave或类似的作品充满了想象......而不是从字面上一个完整的呼叫。)

(Again, as I say, often just an "afterSave" or similar works fantastically...rather than literally a full call.)

下面是一个云的呼叫,节省了18个十亿行code在所有覆盖的网络公司平台的一个典型例子

Here's a typical example of a cloud call that saves 18 billion lines of code in ALL the platforms covered by the dotcom

首先,云计算code ...

First the cloud code...

Parse.Cloud.define("clientRequestHandleInvite", function(request, response)
{
// called from the client, to accept an invite from invitorPerson

var thisUserObj = request.user;
var invitorPersonId = request.params.invitorPersonId;
var theMode = request.params.theMode;

// theMode is likely "accept" or "ignore"

console.log( "clientRequestAcceptInvite called....  invitorPersonId " + invitorPersonId + " By user: " + thisUserObj.id );
console.log( "clientRequestAcceptInvite called....  theMode is " + theMode );

if ( invitorPersonId == undefined || invitorPersonId == "" )
  {
  response.error("Problem in clientRequestAcceptInvite, 'invitorPersonId' missing or blank?");
  return;
  }

var query = new Parse.Query(Parse.User);
query.get(
  invitorPersonId,
    {
    success: function(theInvitorPersonObject)
      {
      console.log("clientRequestFriendRemove ... internal I got the userObj ...('no response' mode)");

      if ( theMode == "accept" )
        {
        createOneNewHaf( thisUserObj, theInvitorPersonObject );
        createOneNewHaf( theInvitorPersonObject, thisUserObj );
        }

      // in both cases "accept" or "ignore", delete the invite in question:
      // and on top of that you have to do it both ways

      deleteFromInvites( theInvitorPersonObject, thisUserObj );
      deleteFromInvites( thisUserObj, theInvitorPersonObject );

      // (those further functions exist in the cloud code)

      // for now we'll just go with the trick of LETTING THOSE RUN
      // so DO NOT this ........... response.success( "removal attempt underway" );
      // it's a huge problem with Parse that (so far, 2014) is poorly handled:
      // READ THIS:
      // parse.com/questions/can-i-use-a-cloud-code-function-within-another-cloud-code-function
      },
    error: function(object,error)
      {
      console.log("clientRequestAcceptInvite ... internal unusual failure: " + error.code + " " + error.message);
      response.error("Problem, internal problem?");
      return;
      }
    }
  );

}
);

如果你是新来解析这是令人难以置信很难搞清楚如何从Android或iOS的调用这些!!

If you are new to Parse it's incredibly hard to figure out how to call these from Android or iOS !!

下面是一个由机器人被称为...

Here's that one being called from Android ...

这会搞乱与HashMaps这样每天为您节省:)

this will save you a day of messing about with HashMaps :)

private static void handleInvite( ParseUser invitor, final boolean accepted )
    {
    String invitorId = invitor.getObjectId();
    // you must SEND IDs, NOT PARSEUSER OBJECTS to cloud code. Sucks!

    String cloudKode;
    cloudKode = (accepted? "accept" : "ignore");

    HashMap<String, Object> dict = new HashMap<String, Object>();
    dict.put( "invitorPersonId", invitorId );
    dict.put( "theMode", cloudKode );

    Toast.makeText(State.mainContext, "contacting...", Toast.LENGTH_SHORT).show();

    ParseCloud.callFunctionInBackground(
        "clientRequestHandleInvite",
         dict,
         new FunctionCallback<Object>()
    {
    @Override
    public void done(Object s, ParseException e)
        {
        Toast.makeText(State.mainContext, "blah", Toast.LENGTH_SHORT).show();
        // be careful with handling the exception on return...
        }
    });

    }

而这里的iOS中云呼叫......嗯,现在,直到你必须做的SWIFT

And here's a cloud call in iOS ... well for now, until you have to do it in SWIFT

-(void)tableView:(UITableView *)tableView
        commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
        forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    int thisRow = indexPath.row;
    PFUser *delFriend = [self.theFriends objectAtIndex:thisRow];

    NSLog(@"you wish to delete .. %@", [delFriend fullName] );

    // note, this cloud call is happily is set and forget
    // there's no return either way. life's like that sometimes

    [PFCloud callFunctionInBackground:@"clientRequestFriendRemove"
            withParameters:@{
                            @"removeThisFriendId":delFriend.objectId
                            }
            block:^(NSString *serverResult, NSError *error)
            {
            if (!error)
                {
                NSLog(@"ok, Return (string) %@", serverResult);
                }
            }];

    [self back];    // that simple
    }

注意作为的iOS /雨燕的经验,在点击至:如何使这个Parse.com云$ C $调用C?其中包括从Parse.com krew意见。

Note For the iOS/Swift experience, click to: How to make this Parse.com cloud code call? which includes comments from the Parse.com krew.

希望这样可以节省别人一些打字,欢呼声

Hope it saves someone some typing, cheers

这篇关于安卓:使用服务器端使用Parse工作时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆