Domanda

My code:

NSString *urlString = [NSString stringWithFormat:@"%@%@%@%@", @"http://api.search.live.net/json.aspx?Appid=am hiding the appid &query=",text,@"&sources=web&web.offset=",offvalue];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];

The JSON response:

SearchResponse =     {
        Errors =         (
                        {
                Code = 1002;
                HelpUrl = "http://msdn.microsoft.com/en-us/library/dd251042.aspx";
                Message = "Parameter has invalid value.";
                Parameter = "SearchRequest.AppId";
                Value = " am hiding the value";
            }
        );
        Query =         {
            SearchTerms = iphone;
        };
        Version = "2.2";
    };
}

What wrong am I doing here.Can anyone please rectify my query??How to use version 2.2 of the bing API

È stato utile?

Soluzione

What is the value of 'text', is this one word or multiple words? You'll need to perform URL_Encode on the parameter 'text' in order to have a valid URL.

See Objective-C and Swift URL encoding Be sure only to have the URL_Encoding on the text-object and not on the whole URL, otherwise "http://" will be encoded as well, resulting in an invalid URL as well

Eg a space should be %20 , you can verify this by adding a NSLog of the URL

Altri suggerimenti

It looks like you entered the wrong AppID judging from.

Parameter = "SearchRequest.AppId";

Make sure that the AppID matches the appID that they assigned your app with the service.

Also (and this sometimes randomly causes issues for me) make sure you put a / at the end of the URL String.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top