I believe the problem here is not the UID regular expression (which I
verified is working as expected) but the way you're retrieving the
UID. opensocial.DataRequest.send is an asynchronous call which means
it's non-blocking -- after send is executed, your other code will
continue to run until the VIEWER information is available at which
point the callback (userIdResponse in this case) is invoked.

Basically, you're trying to use uid too quickly -- since uid is not
initialized, it defaults to undefined (i.e. 0 or false). Asynchronous
programming has a bit of a learning curve, but it can be very
powerful. If I were you, I would retrieve and store the UID when the
application first loads, then load the user interface that allows a
user to add a movie. Then, you have the UID ready if/when addMovie is
invoked later.

Please let me know if you have any more questions about this issue or
asynchronous programming in general.

- Jason

On Sep 11, 10:55 am, laden <[EMAIL PROTECTED]> wrote:
> I am using the following code but I am unable to retreive the user id.
>
> function userIdrequest() {
>     var params = {};
>     params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS]
> = [opensocial.Person.Field.PROFILE_URL];
>     var req = opensocial.newDataRequest();
>     req.add(req.newFetchPersonRequest("VIEWER", params), "viewer");
>     req.send(userIdresponse);
>   };
>
>           function userIdresponse(data) {
>                 var viewer = data.get("viewer").getData();
>                 var profile_url =
> viewer.getField(opensocial.Person.Field.PROFILE_URL);
>                 var regex = /uid=([^&#]+)/;
>                 var result = profile_url.match(regex);
>                 if (result.length == 2) {
>                    var uid = result[1];
>                    return uid;
>                     /* uid now contains the viewer's orkut UID */
>                 } else {
>                   /* there was a problem getting the UID */
>                 }
>
>           };
>
> function addMovie(myMovieId,linkId){
>                 var params = {};
>                 var uid = userIdrequest();
>                 var postdata = {
>                                 movieId : myMovieId,
>                                 userId : uid,
>                                 };
>         params[gadgets.io.RequestParameters.METHOD] =
> gadgets.io.MethodType.POST;
>                 params[gadgets.io.RequestParameters.POST_DATA] =
> gadgets.io.encodeValues(postdata);
>                 var url = "http://myserver.com/addMovie";;
>                 gadgets.io.makeRequest(url, addMovieMsg, params);
>
> }
>
> But I am getting 0 as user id.
> Please help me to solve this problem.
> Thanq in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Orkut Developer Forum" group.
To post to this group, send email to opensocial-orkut@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/opensocial-orkut?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to