Bookmark Bookmark Bookmark Bookmark Bookmark Bookmark Bookmark My Bookmark - Become a Fan on Facebook!

LorenzGames, All about Flash Games!

Follow me on Twitter! Follow Me on Twitter

How to import games to your site from MochiAds

June 27th, 2009 - Category: MochiAds, PHP, Publishers
MochiAds gives you the possibility to directly download the games to your site through JSON.
The problem is that many people has no clue how this thing works, that's why i have created a script that not only allows you to Download how many games you want from theire site, but gives you the possibility to use the button "Post to my site" that is on the page of every game on MochiAds for manuale downloading.

Mochiads Logo

This script will only unpack the JSON, then you will have to put everything in your own Database and downloading the files the way you want wherever you want. For example you can use the method:
file_put_contents("where you want the file to be", file_get_contents("url of the file on mochiads"));

The only thing you have to change in the code is the Publisher ID, you can find your own here.
If you are going to use the manual submission from MochiAds dont forget to add the link to the file where you put this script in "Auto POST URL".
I set the type of games to download to only featured games, if you want to download all just change "featured_games" to "all".
Please enjoy and share. Emoticon

PHP
$pubID = "Here put your Publisher ID";
$gt=$_POST['game_tag'];
$extrag=$_POST['extrag'];
$typeGame="featured_games"; // Change it to 'all' if you want to import all the games.
 
if($gt!=""||$extrag!=""){	
	if($gt!=""){
		$json=file_get_contents("http://www.mochiads.com/feeds/games/".$pubID."/".$gt."/?format=json");
		$n=1;
	}
 
	if($extrag!=""){
		$json=file_get_contents("http://www.mochiads.com/feeds/games/".$pubID."/".$typeGame."/all?format=json&limit=".$extrag);
		$n=$extrag;
	}
 
	$jsonArr=json_decode($json,true);
 
	$g=0;
	while($g<$n){
		$gameArr=$jsonArr["games"][$g];
		$name=$gameArr["name"];
		$description=$gameArr["description"];
		$instructions=$gameArr["instructions"];
		$swfUrl=$gameArr["swf_url"];
		$imgUrl=$gameArr["thumbnail_url"];	
		$category=$gameArr["categories"][0]; // This is an Array [0] will take the first catgeory choosen.		
		$keywords="";
		$nTags=count($gameArr['tags']);
		for($i=0;$i<$nTags;$i++){
			$keywords=$keywords.$gameArr['tags'][$i].' ';
		}
		$width=$gameArr["width"];
		$height=$gameArr["height"];
		$g++;
 
		echo "<a target='_blank' rel='nofollow' href=".$swfUrl." target="_blank"><img style='margin:10px 0px 10px 0px; border: solid 2px #FFFFFF;' src=".$imgUrl."> ".$name."</a><br>";
	}
}


HTML
 <br><input name="extrag" value="5" size="5" type="text"><br>MochiAds Games <input value="Download" name="Submit" type="submit"><br> 



Article Comments


buzzknow - May 2nd, 2010
hi

this is i'm looking for Emoticon

btw i want to create simple site and display 1 games, just for testing purpose, but when i submit score, my score wasnt display at leaderboard widget, even the widget has my pub ID Emoticon

what should i do?

thanks

Write a Comment: