What parameters should I use in order to get search result from only a site say abcd.com using bing 2.0 API? I am trying to fetch results in JSON format. Can anybody help?
fresh code to the masses
$query = array
(
'AppId' => <API_KEY>,
'sources' => 'Web',
'query' => 'site:www.tipografix.ro '.$keywords,
'Version' => '2.0',
'Options' => 'EnableHighlighting',
'Web.Count' => $per_page,
'Web.Offset' => $page_num,
'Web.Options' => 'DisableHostCollapsing DisableQueryAlterations'
);
$request = 'http://api.bing.net/json.aspx?'.http_build_query($query);
$response = file_get_contents($request);
$jsonobj = json_decode($response);
Not sure how the JSON format of the API works but in the query parameter put in "site:abcd.com bacon" where bacon is your original query.
I'm using the XML format so if I'd send a request to:
http://api.search.live.net/xml.aspx?Appid=________&query=site%3Aabcd.com+bacon&sources=web&web.count=5&web.offset=0
Related
A user has accepted my Facebook app. I can now access some of their data. It is returned as a graphObject, which contains something like:
Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => 11111 [first_name] => Bob [gender] => male [last_name] => Builder [link] => https://www.facebook.com/app_scoped_user_id/11111/ [locale] => de_DE [name] => Bob Builder [timezone] => 2 [updated_time] => 2014-02-14T14:35:54+0000 [verified] => 1 ) )
Unfortunately I cannot get at the data inside this object. Reading it like an array throws an error:
$fbid = $graphObject['id']; // Cannot use object of type Facebook\GraphObject as array
$fbid = $graphObject->id; // Undefined property: Facebook\GraphObject::$id
How can I get at the ID?
If you have casted the response as a GraphObject by using one of the following two methods:
// Get the response typed as a GraphLocation
$loc = $response->getGraphObject(GraphLocation::className());
// or convert the base object previously accessed
// $loc = $object->cast(GraphLocation::className());
You can use the Get properties of the graph object, depending on what kind of object you've casted it as... here's an example for the GraphUser Object:
echo $user->getName();
Or, if you know the name of the property (as shown in the base data), you can use getProperty():
echo $object->getProperty('name');
So in your example, you can use the following to get the id property:
echo $user->getProperty('id');
More examples and documentation here
In the New version of Graph API getProperty does not work.
For the New version Graph API v2.5 of Facebook Read read data as below :
$fb = new \Facebook\Facebook([
'app_id' => 'APPIDHERE',
'app_secret' => 'SECRET HERE',
'default_graph_version' => 'v2.5',
]);
$asscee_t ="ACCESS TOKEN HERE";
$response = $fb->get('/me/friends', $asscee_t);
$get_data = $response->getDecodedBody(); // for Array resonse
//$get_data = $response->getDecodedBody(); // For Json format result only
echo $get_data['summary']['total_count']; die; // Get total number of Friends
Note that from API version >= 5.0.0 getProperty() has been renamed to getField(). It will be removed from >= v6. So
Instead of
$user->getProperty('name')
Use
$user->getField('name')
Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.
I've upgraded to Zend Framework v1.12.3 because it supports the TwitterAPI v1.1 with Zend_Service_Twitter. Before, I've used the TwitterAPI 1.0 (prior ZF 1.12.3) which works well, but that's gonna change in march 2013.
If I call the TwitterAPI v1.1 with the following ZF 1.12.3 code, I keep getting a strange error which I can't explain to myself:
Code:
$twitterService = new Zend_Service_Twitter(array(
'consumerKey' => $this->config['consumerKey'],
'consumerSecret' => $this->config['consumerSecret'],
'username' => $twitterVO->getTwitterUserName(),
'accessToken' => $accessToken // unserialized object
));
$response = $twitterService->statusesUpdate("TEST");
And that's the error which I get. It doesn't matter which function I call (in this case it's statusesUpdate("Test")):
The message is "Invalid chunk size "" unable to read chunked body". The "type" attribute within the array shows a "->". That's also a bit suspect but I couldn't find out where it comes from.
Does anyone have a working example with Zend Framework 1.12.3?
Since ZF 1.12, the Twitter app Oauth parameters can be given in the Zend_Service_Twitter constructor, but consumerKey and consumerSecret must go under the "oauthOptions" array.
This works for me:
$accessToken = new Zend_Oauth_Token_Access();
$accessToken->setToken('YourAccessToken');
$accessToken->setTokenSecret('YourAccessTokenSecret');
$twitter = new Zend_Service_Twitter(
array(
'username' => 'YourUsername',
'accessToken' => $accessToken,
'oauthOptions' => array(
'consumerKey' => 'YourConsumerKey',
'consumerSecret' => 'YourConsumerSecret'
)
)
);
$result = $twitter->statusesUserTimeline('TEST');
I am storing the linkedin access token in database. This is the token that is stored in my database:
oauth_token=xxxxxxxxxxxxxxxxxxx&oauth_token_secret=xxxxxxxxxxxxxxxxxxx&oauth_expires_in=5183998&oauth_authorization_expires_in=5183998
I want to retrieve the linkedin connections using this access token. I am trying to make a call like this:
$a = new Zend_Oauth_Token_Access();
$client = $a->getHttpClient( array(
'siteUrl' => LIN_SITE_URL,
'callbackUrl' => LIN_SITE_CALLBACK_URL,
'requestTokenUrl' => LIN_REQUEST_TOKEN_URL,
'userAuthorizationUrl' => LIN_USER_AUTHORIZATION_URL,
'accessTokenUrl' => LIN_ACCESS_TOKEN_URL,
'consumerKey' => LIN_CONSUMER_KEY,
'consumerSecret' => LIN_CONSUMER_SECRET
) );
$client->setUri('http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name,picture-url)');
$client->setParameterGet('token',$linToken);
$client->setMethod(Zend_Http_Client::GET);
$response = $client->request();
$content = $response->getBody();
$data = json_decode(Zend_Json::fromXml($content, false));
print_r($data); echo "<br/>";
The error i am getting here is:
stdClass Object ( [error] => stdClass Object ( [status] => 404 [timestamp] => 1349429996351 [request-id] => 8U8A1UNF1V [error-code] => 0 [message] => Could not find person based on: ~ ) )
Is this the correct way to make a call or am i doing something wrong here. I am using zend framework.
Thanks.
I was able to solve the problem by passing the outh_token and outh_token_secret as an array to the setParams() of Zend_Oauth_Token_Access as below:
$a = new Zend_Oauth_Token_Access;
$a->setParams(array(
'oauth_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
In your code example I don't see where you're setting the access token and secret. I just see that you're instantiating the $a variable:
$a = new Zend_Oauth_Token_Access();
Are you retrieving the access token and secret from you database then setting it to the $a variable? Something like this:
$a->setToken($row['token'])
->setTokenSecret($row['secret']);
By the way, this is a good reference for using Zend and LinkedIn: http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/
Is there any way to change the Facebook album privacy settings with graph api?
I'm trying to find out, but all I could found is how to get the privacy settings using fql, but not to set.
I'm creating the album as follow
$postdata = http_build_query(array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
) $context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false, $context));
$albumid = $result->id;
Now if I add privacy=>"value", it gives $albumid=null.
I'm not sure where I need to add privacy parameter.
When you create an album, you can send these parameters in post request.
name, message, location and privacy.
Value of privacy field can be set like this,
privacy={value: "CUSTOM"} (send this as post parameter)
The value field may specify one of the following strings:
EVERYONE, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM .
As facebook docs sucks, there's no mention about it on albums object page.
However, you can read it on post object.
Edit: (after comments)
In php sdk you can do something like this,
$ret_obj = $facebook->api('me/albums', 'POST',
array(
'privacy' => '{value: "CUSTOM"}',
'location' => 'India'
));
The document of creating an album is put in https://developers.facebook.com/docs/reference/api/user/#albums
Privacy setting is a json-style string. So you could create an array() and use json_encode() to generate it.
with php sdk it is also possible as php style #kaur
$ret_obj = $facebook->api('/me/albums/', 'POST', array(
'source' => '#' . $photo,
'message' => 'Picture uploaded',
'location' => 'Goran',
'privacy'=> array('value'=>'EVERYONE'), //'privacy'=> '{value: "EVERYONE"}', //worked too!! SELF, ALL_FRIENDS, EVERYONE
)
);