Jump to content
  • entries
    945
  • comments
    5,899
  • views
    929,970

Automate your social media accounts with the Steam web API


Josh

1,748 views

 Share

blog-0297139001482114329.jpg

Keeping your social media accounts active with screenshots, videos, and updates is important, but as an indie developer you probably don't have time to post on there every day. In this blog I will show you how to easily automate your social media accounts so that a constant stream of new content is going out to your fans.

 

First, you will need to create a free account with dlvr.it. Connect your social media accounts to it. Facebook, Twitter, and Google+ are the important ones.

 

Now you need some RSS feeds to act as inputs. There is an RSS feed for your game's announcements here:

http://steamcommunity.com/games/YOUR_APP_ID/rss/

 

Set this RSS feed as an input in your dlvr.it account and it will make posts automatically to your social media account.

 

We can use the Steam web API to create an RSS feed of your game's screenshots, videos, and Workshop items. The code below will do exactly that. Just input your game's app ID and a web API key you generate in the Steamworks interface:

/*----------------------------------------------------*/

/* This code is free to use. Do not redistribute it. */

/* Leadwerks Software 2016 */

/*----------------------------------------------------*/

 

$appID = 'xxxxxxx';

$webAPIKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$recordCount=20;

$fileType = '-1';

$queryType = 1;

 

function LoadXML($path)

{

$content = utf8_encode(file_get_contents($path));

$content = str_replace(chr(11),'',$content);

if (trim($content=='')) return NULL;

return simplexml_load_string($content);

}

 

$steamcontent = @LoadXML('http://api.steampowered.com/IPublishedFileService/QueryFiles/v0001?key='.$webAPIKey.'&format=xml&query_type='.$queryType.'&page=1&numperpage='.$recordCount.'&appid='.$appID.'&filetype='.$fileType.'&return_vote_data=1&return_short_description=1');

 

function clean($string)

{

return preg_replace('/[^A-Za-z0-9\- ().,!]/', '', $string); // Removes special chars.

}

 

function truncate($string, $length)

{

if (strlen($string)>$length)

{

return substr($string,0,$length-3)."...";

}

else

{

return substr($string,0,$length);

}

}

 

echo('<?xml version="1.0" encoding="UTF-8" ?>'."\n");

echo('<rss version="2.0">'."\n");

echo('<channel>'."\n");

echo("<title>Leadwerks Community Activity</title>"."\n");

echo('<link>http://www.leadwerks.com</link>'."\n");

echo("<description>Activity feed from Leadwerks Community Hub on Steam.</description>"."\n");

 

for ($i=0; $i<min($recordCount,$steamcontent->total); $i=$i+1)

{

/* Only show screenshots above a certain score */

if (($steamcontent->publishedfiledetails->message[$i]->vote_data->score>0.4 || $steamcontent->publishedfiledetails->message[$i]->file_type!=5) && $steamcontent->publishedfiledetails->message[$i]->result==1)

{

$file_type = $steamcontent->publishedfiledetails->message[$i]->file_type;

if ($file_type!=0 && $file_type!=5 && $file_type!=4) continue;

echo("<item>"."\n");

 

$title = clean($steamcontent->publishedfiledetails->message[$i]->title);

if ($title=="") $title = truncate(clean($steamcontent->publishedfiledetails->message[$i]->short_description),35);

if ($title=="Screenshot") $title = "";

 

/* Get author name */

$userid = $steamcontent->publishedfiledetails->message[$i]->creator;

$userdata = simplexml_load_file('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?format=xml&key='.$webAPIKey.'&steamids='.$userid);

$username = $userdata->players->player[0]->personaname;

 

if ($steamcontent->publishedfiledetails->message[$i]->file_type==0)

{

echo("\t<title>Workshop item by ".$username.": ".$title."</title>\n");

}

else if ($steamcontent->publishedfiledetails->message[$i]->file_type==5)

{

echo("\t<title>Screenshot by ".$username.": ".$title."</title>\n");

}

else if ($steamcontent->publishedfiledetails->message[$i]->file_type==4)

{

echo("\t<title>Video by ".$username.": ".$title."</title>\n");

}

else

{

continue;

}

 

if ($steamcontent->publishedfiledetails->message[$i]->file_type==4)

{

echo("\t<link>http://www.youtube.com/watch?v=".$steamcontent->publishedfiledetails->message[$i]->youtubevideoid."</link>\n");

}

else

{

echo("\t<link>http://steamcommunity.com/sharedfiles/filedetails/?id=".$steamcontent->publishedfiledetails->message[$i]->publishedfileid."</link>\n");

}

 

echo("\t<description>\n\t\t<![CDATA[");

 

$description = clean($steamcontent->publishedfiledetails->message[$i]->short_description);

$description = $description.' #gamedev #indiedev';

 

if ($steamcontent->publishedfiledetails->message[$i]->file_type==4)

{

if (!empty($description)) echo('<p />'.$description);

echo("<br />http://www.youtube.com/watch?v=".$steamcontent->publishedfiledetails->message[$i]->youtubevideoid);

}

else

{

echo("<p /><a href='http://steamcommunity.com/sharedfiles/filedetails/?id=".$steamcontent->publishedfiledetails->message[$i]->publishedfileid."'><img width='600px;' src='".$steamcontent->publishedfiledetails->message[$i]->preview_url."' /></a>");

if (!empty($description)) echo('<br />'.$description);

}

 

echo("]]>\n\t</description>\n");

 

if ($steamcontent->publishedfiledetails->message[$i]->file_type!=4)

{

echo("<enclosure url='".$steamcontent->publishedfiledetails->message[$i]->preview_url."' length='".$steamcontent->publishedfiledetails->message[$i]->file_size."' type='image/jpeg' />");

}

 

echo("<guid>".$steamcontent->publishedfiledetails->message[$i]->publishedfileid."</guid>");

$displaytime = $steamcontent->publishedfiledetails->message[$i]->time_created;

$displaytime = date('D, d M Y, h:m:s', intval($displaytime));

 

echo("\t<pubDate>".$displaytime."</pubDate>\n");

 

echo("\t<category>gamedev</category>\n");

echo("\t<category>indiedev</category>\n");

echo("\t<category>Leadwerks</category>\n");

 

echo("</item>\n");

}

}

 

echo("</channel>\n");

echo("</rss>\n");

 

There are a lot of settings in dlvr.it you can experiment with, but this is enough to get you running. Once this is set up you can keep your social media accounts active without having to log in and post items manually several times a day.

  • Upvote 3
 Share

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...