PHP Function Help
Here is the function im trying to us, its held in a file called function.php
public function updateProfile($name = null, $email = null, $url = null, $location = null, $description = null)
{
// validate parameters
if($name === null && $email === null && $url === null && $location === null && $description === null) throw new TwitterException('Specify at least one parameter.');
if($name !== null && strlen($name) > 40) throw new TwitterException('Maximum 40 characters allowed for name.');
if($email !== null && strlen($email) > 40) throw new TwitterException('Maximum 40 characters allowed for email.');
if($url !== null && strlen($url) > 100) throw new TwitterException('Maximum 100 characters allowed for url.');
if($location !== null && strlen($location) > 30) throw new TwitterException('Maximu开发者_如何学运维m 30 characters allowed for location.');
if($description !== null && strlen($description) > 160) throw new TwitterException('Maximum 160 characters allowed for description.');
// build parameters
if($name !== null) $aParameters['name'] = (string) $name;
if($email !== null) $aParameters['email'] = (string) $email;
if($url !== null) $aParameters['url'] = (string) $url;
if($location !== null) $aParameters['location'] = (string) $location;
if($description !== null) $aParameters['description'] = (string) $description;
// make the call
$response = $this->doCall('account/update_profile.xml', $aParameters, true);
// convert into xml-object
$xml = @simplexml_load_string($response);
// validate
if($xml == false) throw new TwitterException('invalid body');
// return
return (array) $this->userXMLToArray($xml, true);
}
In index.php I have:
<php?
require_once("function.php");
$Twitter = new Twitter;
?>
I need to update the profile location?
Once you require the file, all you need to do is call the function:
<?php
require_once("function.php");
updateProfile("username", "email", "url", "location", "description");
?>
However, your function seems to be part of a class - but your example code doesn't show the class. If it is part of a class, I'll assume it's called 'Twitter'. In that case the code your using is close. It would be along the lines of:
<?php
require_once("function.php");
$Twitter = new Twitter;
$Twitter->updateProfile("username", "email", "url", "location", "description");
?>
Of course the class would have to do some kind of authentication, which the function your posted seems to refer to - $this->doCall()
. Again the bulk of the class is missing, so this function by itself wouldn't do what your looking for.
Are you just asking how to call the function? I'm not familiar with the Twitter API, but I expect it'd be something like this:
$Twitter->updateProfile(null, null, null, 'new-location');
Each argument is optional and has a default value of null
, so if you only want to pass in a particular argument, then just use null
for all arguments before that one.
精彩评论