Group Name Grabber

Our first webservice is now live! This service is free for any group member to use. If you use it, please post a comment here so we can see some of the great ideas you come up with!

Instructions and code after the break.

How to use it:

If you pass it a valid group key, it will return the group name, as found in SL search. If the group is not listed – either because it is not set to show in search, or the group key isn’t right, it returns an X.

The URL to check the name is:

http:/groupname.scriptacedemy.org/MY_GROUP_KEY – where “MY_GROUP_KEY” is the SL UUID of the group.

Here is an example script to show how it could be used:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Group Name Grabber
//
// By Hippyjim Starbrook
 
// A key variable to keep track of our web requests
key httpid;
 
default
{
 
    // On touch, start the request
    touch_start(integer total_number)
    {
        // Get a list containing my group details
        list details = llGetObjectDetails(llGetKey(), [OBJECT_GROUP]);
 
        // Grab the key as a string from that list
        string groupkey = llList2String(details, 0);
 
        // Make the web request including the group key as part of the url
        httpid = llHTTPRequest("http://groupname.scriptacademy.org/" + groupkey, [HTTP_METHOD, "GET"], "");
    }
 
 
    // When the web replies, say the result
    http_response(key id, integer status, list data, string body)
    {
 
        // check the web replied ok, and that we made the request properly
        if (status == 200 && id == httpid)
        {
            // if the web replied with an X, say it's a private group
            if (body == "X")
            {
                llSay(0, "I'm in a private group");
            }
            // if not, say the group name
            else
            {
                llSay(0, "I'm in " + body);
            }
        }
    }
}

The PHP on the server side is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
<?php 
 
/*
*
*  Group Name Grabber PHP script - By Hippyjim Starbrook
*
*  usage:
*
*  send a GET request with ?ky= the group key to get the name of a group with the given key
*  if the request is malformed, or the key doesn't exist, returns X
*
*/
 
$groupKey = $_GET["ky"];
 
// create a new cURL resource
$ch = curl_init();
 
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://world.secondlife.com/group/".$groupKey);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
// grab URL and pass it to the browser
$dump = curl_e xec($ch); // note the space in "curl_e xec" must be removed for it to work - only added here due to a limit in the blog software
 
// close cURL resource, and free up system resources
curl_close($ch);
 
// remove all HTML tags from the result, except the <h1> tags (which will surround our group name)
$dump = strip_tags($dump, "<h1>");
 
// if the reply doesn't include the phrase "The specified key does not exist" take the page apart
if (!strpos($dump, "The specified key does not exist"))
{
	// find the position of the phrase "Group:" in the page, as that shows the start of our group name
	$groupPos = strpos($dump, "Group:")+ 6;
	// find the closing </h1> tag immediately after "Group:" as that signifies the end of our group name
	$endPos = strpos($dump, "</h1>", $groupPos);
	// our group name is the string in between these two points
	$groupName = trim(substr($dump, $groupPos, $endPos-$groupPos));
	// output the group name
	echo $groupName;
}
// otherwise output an X
else
{
	echo "X";
}
?>

1 comment so far ↓

#1 Gruppenname oder Gruppen UUID herausbekommen on 07.11.12 at 7:38 am

[…] […]

You must log in to post a comment.