开发者

Millennial Media PHP Request not returning anything

开发者 https://www.devze.com 2023-04-07 23:28 出处:网络
So I can\'t figure out what it is about my code that isn\'t working. Basically, I\'m trying to get a Flash actionscript method of getting Millennial Media ads into an app I\'ve been making. But I\'m a

So I can't figure out what it is about my code that isn't working. Basically, I'm trying to get a Flash actionscript method of getting Millennial Media ads into an app I've been making. But I'm a little stuck because I can't seem to get a response from Millennial Media when I send off the PHP from my actionscript.

Here's the PHP:

<?php
/*--------------------------------------------------------------*/
/* Millennial Media PHP Ad Coding, v.7.4.20                     */
/* Copyright Millennial Media, Inc. 2006                        */
/*                                                              */
/* The following code requires PHP >= 4.3.0 and                 */
/* allow_url_fopen 1 set in php.ini file.                       */
/*                                                              */
/* NOTE:                                                        */
/* It is recommended that you lower the default_socket_timeout  */
/* value in the php.ini file to 5 seconds.                      */
/* This will prevent network connectivity from affecting        */
/* page loading.                                                */
/*--------------------------------------------------------------*/

/*------- Publisher Specific Section -------*/
$mm_placementid = XXXXX;
$mm_adserver = "ads.mp.mydas.mobi";

/* The default response will be echo'd on the page     */
/* if no Ad is returned, so any valid WML/XHTML string */
/* is acceptable.                                      */
$mm_default_response = "";

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

/*----------- BEGIN AD INITIALIZATION ----------*/
/*----- PLEASE DO NOT EDIT BELOW THIS LINE -----*/
$mm_id = "NONE";
$mm_ua = "NONE";
@$mm_ip = $_SERVER['REMOTE_ADDR'];

if (isset($_SERVER['HTTP_USER_AGENT'] )){
    $mm_ua = $_SERVER['HTTP_USER_AGENT'];
} 

if (isset($_SERVER['HTTP_X_UP_SUBNO'])) {
          $mm_id = $_SERVER['HTTP_X_UP_SUBNO'];
} elseif (isset($_SERVER['HTTP_XID'])) {
          $mm_id = $_SERVER['HTTP_XID'];
} elseif (isset($_SERVER['HTTP_CLIENTID'])) {
          $mm_id = $_SERVER['HTTP_CLIENTID'];
} else {
          $mm_id = $_SERVER['REMOTE_ADDR'];
}

$mm_url = "http://$mm_adserver/getAd.php5?apid=$mm_placementid&auid="
          . urlencode($mm_id) . "&ua=" . urlencode($mm_ua) . "&uip=" . urlencode($mm_id);
echo $mm_url;
/*------------ END AD INITIALIZATION -----------*/
?>

This basically sends back a big long URL that I then use to display the ad inside my Actionscript file like so:

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.LocationChangeEvent;
    import flash.events.UncaughtErrorEvent;
    import flash.geom.Rectangle;
    import flash.media.StageWebView;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLStream;
    import flash.net.URLVariables;

    public class Main extends Sprite
    {
        public var s:String = new String();
        public var final:String = new String();
        private var _swv:StageWebView;

        public function Main()
        {           
            initRequest();          
        } 

        public function initRequest():void {
            var request:URLRequest = new URLRequest("http://www.xxx.com.au/connect copy.php");

            request.method = URLRequestMethod.POST;

            var recVars:URLVariables = new URLVariables();

            request.data = recVars;     

            var loader:URLLoader = new URLLoader(request);
            loader.addEventListener(Event.COMPLETE, onComplete);
            loader.dataFormat = URLLoaderDataFormat.TEXT;
            loader.load(request);           

            function onComplete(event:Event):void{
                s = event.target.data;
            }           
            AdDisplay();    
        }


        public function AdDisplay():void {

            if (! _swv) {
                _swv = new StageWebView () ;
                _swv.v开发者_开发技巧iewPort = new Rectangle(stage.stageWidth/2 - 175,stage.stageHeight/2,500,500);

                _swv.loadURL(s);
                _swv.stage = stage;
            }
        }
        }
    }

Now, with trace statements, I know that the URL that gets returned is whole and can be used.

Currently it returns:

http://ads.mp.mydas.mobi/getAd.php5?apid=56926&auid=144.132.17.0&ua=Mozilla%2F5.0+%28Android%3B+U%3B+en-GB%29+AppleWebKit%2F531.9+%28KHTML%2C+like+Gecko%29+AdobeAIR%2F2.6&uip=144.132.17.0

But then when I put it into the StageWebView box to be shown, it doesn't show anything! I have gotten it to work previously, not sure how, but it would only show up ONE ad, and that was it, and it would only do that some of the time. I've been testing it in my browser, and have come to the conclusion that it's something to do with the &uip= etc. etc. Because, if I replace that IP address with the one given in the examples 63.145.58.2 - it works and I get a whole bunch of different ads from groupon.

I'm not sure if it's because I'm on wireless here and as such it just plain refuses or something, or what's going on, but some help would be great if anyone can think of anything that I'm missing, or knows something about Millennial Media not showing ads 100% of the time.

Oh! Final thing, I did try to create a house ad to fill in the gaps when the ads were working, but that didn't work either...

Thanks everyone!


I am pretty sure IP address with last octet 0 isn't really good address. From what i can recall routing to/from this kind of address will be sporadic at best depending on the route itself :)

Apart from that can you make sure (with traces and/or debug) that the actual loadUrl method is performing well ? I can't see the code behind it, but you should check if there is some error events handling and stuff that are not logged or propagated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号