I am trying to tweet an image using php. I have read the documentation and followed a some tutorials. I don't have any problem when sending a message; however, it does not work with images. I can not find where my mistake is, can anyone help?? I would deeply appreciate it.
<?php
$comments = $_POST['comment'];
if (isset($_POST['Twitter']))
{
require_once('twitter/codebird-php/src/codebird.php');
\Codebird\Codebird::setConsumerKey("xxxxxx","xxxxxx");
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("xxxxxx", "xxxxxxxxxx");
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
$reply = $cb->statuses_update($params);
echo "You have posted your message succesfully";
}
else{
echo "You havent posted anythingh";
}
?>
You need to supply Twitter the fully qualified URI to your image.
You have the following code:
$params = array(
'status' => $comments,
'media[]' => "/images/image1.jpg"
);
Unfortunately, that's not a complete URL to an image, it's a relative URL. Instead, you need to provide something along the lines of this:
$params = array(
'status' => $comments,
'media[]' => "http://www.example.com/images/image1.jpg"
);
In addition, according to the Twitter API v1 documentation, you need to use statuses/update_with_media instead of statuses/update.
If you are using Twitter API v1, Twitter also recommends using v1.1 instead.
Related
I am working with an existing website,(I am new to this site),I have to find and use the view/transaction_detail page. How can I do this? How can I find the exact path of the file
Here is my code
public function transaction_wallet()
{
//echo "Om Success3";
$customer_id = $this->session->userdata('customer_id');
$customer = $this->site->getRowById('customer_information', 'customer_id', $customer_id);
if($customer->sales_active != 1){
$this->session->set_flashdata('danger_msg', 'Sorry, You have not active !');
redirect('customer/customer_dashboard');
}
$getWallet = $this->site->getRowsByCondition('wallet_transaction', array('customer_id'=>$customer_id), array('id','desc'), 1);
$wallet_balance = !empty($getWallet) ? $getWallet[0]->balance : 0;
$company_info = $this->site->getRowsByCondition('company_information');
$data = array(
'title' => 'Transaction Wallets',
'customer' => objectToArray($customer),
'customer_id' => $customer_id,
'wallet_balance' => $wallet_balance,
'company_info' => $company_info
);
$content = $this->parser->parse('website/customer/transaction_wallet', $data, true);
$this->template->full_customer_html_view($content);
}
If I understand your question correctly, you want to find the file in your project-structure, of which you know the http-path.
A easy way is to go to the page, view the page source and look for an specific codepart.
Also, you can look for a word on the page itself which has nothing to do with a framework syntax.
For example you find a header "Tuesday is moneyday" or a class, "class="moneytable".
Go to your project and simply use the search tool of your IDE to find "Tuesday is moneyday" or "moneytable".
Hi I'm making a web service in cakephp for an android app. I am getting the request and the respose is being send but the response is not visible on the client's end. My code is as shown below. Can there be some other method to send the response.
public function AndroidApp() {
if (isset($_POST["myHttpData"])) {
$coupon = trim($_POST["myHttpData"]);
$couponId = $this->Code->find('all', array(
'conditions' => array(
'Code.coupon_code' => $coupon,
'Code.status' => 'Used'
),
'fields' => array('Code.id')));
$studentAssessmentId = $this->StudentAssessment->find('all', array(
'conditions' => array(
'StudentAssessment.code_id' => $couponId[0]['Code']['id'],
'StudentAssessment.status' => 'Complete'
),
'fields' => array('StudentAssessment.id')));
$scores = $this->AssessmentScore->find('all', array(
'conditions' => array(
'AssessmentScore.student_assessment_id' => $studentAssessmentId[0]['StudentAssessment']['id']
),
'fields' => array('AssessmentScore.score')));
$json = array();
$assessment_data = array();
//debug($scores);
$i = 0;
foreach ($scores as $score) {
$assessment_data[$i] = array("score" => $score['AssessmentScore']['score']);
$i+=1;
}
header('Content-type: application/json');
$json['success'] = $assessment_data;
$android = json_encode($json);
} else {
$json['error'] = "Sorry, no score is available for this coupon code!";
$android = json_encode($json);
}
echo $android;
code smell, non-cakephp standards
First of all, as mentioned in comments by others, you're not using the CakePHP request/response objects. Because of this, you're overly complicating things. See the documentation here;
http://book.cakephp.org/2.0/en/controllers/request-response.html
http://book.cakephp.org/2.0/en/controllers/request-response.html#dealing-with-content-types
And
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
The $scores loop to reformat the query results is probably redundant if you replace the find('all') with find('list'), using 'score' as display field. See the documentation here http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find-list
bugs
There also seems to be some bugs in your code;
the content-type header is only sent if $_POST["myHttpData"] is present.
you're only checking if $_POST["myHttpData"] is present, not if it actually contains any data (empty)
you're not checking if the various queries return a result. This will cause errors in your code if a query did not return anything! For example, you assume that $couponId[0]['Code']['id'] is present (but it won't be if the coupon-code was not found)
possible answer
Apart from these issues, the most probable cause for your problem is that you did not disable 'autoRender'. Therefore CakePHP will also render the view after you've output your JSON, causing a malformed JSON response.
public function AndroidApp() {
$this->autoRender = false;
// rest of your code here
}
I am using SoapClient to pull data out of a sharepoint list. If its a normal text field it works fine and gives me the image. I can even attach the image to the individual list elements and link it into another field and get the image that way. The problem with that is it asks me to log in to my sharepoint account whenever I access the page, which obviously a normal user of my site will not be able to do.
First, if there is a way around this, that will be a sufficient answer because that is my ideal way of doing it.
However, if the better way is to make a picture gallery and then pull the pictures from there then that isn't a problem.
Basically what I need to know is how to use the Imaging library and maybe the GetItemsByIds method? I am very new to soap and sharepoint in general so I appologize for what may be trivial questions but I really need to know how to do this and I can find no resource on the internet that explains what I need to know (if there is one, link it!). Keep in mind, I have to do this in PHP.
Here is some code that I use to pull the list data:
<?php
$authParams = array(
'login' => 'username',
'password' => 'pass'
);
$listName = "{GUID}";
$rowLimit = '500';
$wsdl = "list.wsdl";
$soapClient = new SoapClient($wsdl, $authParams);
$params = array(
'listName' => $listName,
'rowLimit' => $rowLimit;
);
echo file_get_contents($wsdl, FILE_TEXT, stream_context_create(array('http' => array('timeout' => 1))), 0, 1);
$rawXMLresponse = null;
try{
$rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
echo 'Fault code: '.$fault->faultcode;
echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");
?>
//do the useful thing
<?php
unset($soapClient);
?>
It was an issue with the user permissions. Once we had an account with the correct permissions, it worked fine.
I'm building a little backoffice for my site and I want to display the webmaster tools data within it, I cannot for the life of me figure this out!
Does anyone have any PHP examples of pulling data from webmaster tools using the API with PHP, I'm not getting the documentation and have found a php class that looks like it no longer works, but is there a working one already out there?
If I had an example to start with I think I could figure out the rest, I have been googling this for a couple of days now and have not had any success.
If I could just pull a list of sites belonging to my account that would be a start!!
For the record I have been digging through the docs at google, but I can't be the first person to have wanted to do this, so there must be people who have got this working!
Any Takers on throwing me a bone?
Iain
Here is a working example to fetch the sites list. I used my xhttp class, which is a PHP cURL wrapper, to hide the finer details in using cURL.
<?php
// Set account login info
$data['post'] = array(
'accountType' => 'HOSTED_OR_GOOGLE', // indicates a Google account
'Email' => '', // full email address
'Passwd' => '',
'service' => 'sitemaps', // Name of the Google service
'source' => 'codecri.me-example-1.0' // Application's name'
);
// POST request
$response = xhttp::fetch('https://www.google.com/accounts/ClientLogin', $data);
// Extract Auth
preg_match('/Auth=(.+)/', $response['body'], $matches);
$auth = $matches[1];
$data = array();
$data['headers'] = array(
'Authorization' => 'GoogleLogin auth="'.$auth.'"',
);
// GET request
$response = xhttp::fetch('https://www.google.com/webmasters/tools/feeds/sites/', $data);
echo $response['body'];
?>
First thing the script does is to get an Authorization key via Google's ClientLogin. The service name used is sitemaps. You could also use OAuth or Oauth2 or AuthSub.
Next is to fetch the API URL endpoint for getting the sites list and just adding an Authorization header field.
UPDATE: APRIL 20, 2012
CLIENT LOGIN method as illustrated in the above script example won't work anymore because its deprecated by Google. See details here: https://developers.google.com/accounts/docs/AuthForInstalledApps
The best solution would be to use Oauth 2.0 to connect to Google webmaster tools API.
You can use this class to get data: This has been tested, help you to get
TOP_PAGES, TOP_QUERIES,CRAWL_ERRORS, CONTENT_ERRORS,CONTENT_KEYWORDS, INTERNAL_LINKS, EXTERNAL_LINKS, SOCIAL_ACTIVITY
https://github.com/eyecatchup/php-webmaster-tools-downloads
Hope this may help you.
Assuming you have your Application setup correctly, here's an example of the approach I took:
// Authenticate through OAuth 2.0
$credentials = new Google_Auth_AssertionCredentials(
'1111111111-somebigemail#developer.gserviceaccount.com',
[Google_Service_Webmasters::WEBMASTERS_READONLY],
file_get_contents( 'path-to-your-key.p12' )
);
$client = new Google_Client();
$client->setAssertionCredentials( $credentials );
if ( $client->getAuth()->isAccessTokenExpired() ) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Webmasters($client);
// Setup our Search Analytics Query object
$search = new Google_Service_Webmasters_SearchAnalyticsQueryRequest;
$search->setStartDate( date( 'Y-m-d', strtotime( '1 month ago' ) ) );
$search->setEndDate( date( 'Y-m-d', strtotime( 'now' ) ) );
$search->setDimensions( array( 'query' ) );
$search->setRowLimit( 50 );
// Pass our Search Analytics Query object as the second param to our searchanalytics query() method
$results = $service->searchanalytics->query( $url, $search, $options )->getRows();
// Build a CSV
if ( ! empty( $results ) ) {
// Setup our header row
$csv = "Rank,Query,Clicks,Impressions,CTR,Position\r\n";
foreach ( $results as $key => $result ) {
// Columns
$columns = array(
$key + 1,
$result->keys[0],
$result->clicks,
$result->impressions,
round( $result->ctr * 100, 2 ) . '%',
round( $result->position, 1 ),
);
$csv .= '"' . implode( '","', $columns ) . '"' . "\r\n";
}
file_put_contents( dirname( __FILE__ ) . '/data.csv' );
}
I have a full article I just posted on my blog that has an example class I started to write as a wrapper for both Webmaster Tools API and Analytics API. Feel free to use this as a reference:
http://robido.com/php/a-google-webmaster-tools-api-php-example-using-search-analytics-api-to-download-search-analytics-data-as-csv-with-the-new-oauth-2-0-method/
hello i need somehow to get top Regional interest and interest over time from
http://www.google.com/trends?q=lingerie+&ctab=0&geo=id&date=all&sort=0
or better
http://www.google.com/insights/search/#q=lingerie&geo=ID&cmpt=q
so i found out that we have to login to export data can anybody give me an example doing this with our google username and password? maybe using curl to export the data? or something else
Thanks for looking in
Adam Ramadhan
Just to be quick about it, I used my xhttp class which is a curl wrapper, and I think the code is easy enough to follow.
<?php
header('content-type: text/plain');
// Set account login info
$data['post'] = array(
'accountType' => 'HOSTED_OR_GOOGLE', // indicates a Google account
'Email' => '', // full email address
'Passwd' => '',
'service' => 'trendspro', // Name of the Google service
'source' => 'codecri.me-example-1.0' // Application's name, e.g. companyName-applicationName-versionID
);
$response = xhttp::fetch('https://www.google.com/accounts/ClientLogin', $data);
// Test if unsuccessful
if(!$response['successful']) {
echo 'response: '; print_r($response);
die();
}
// Extract SID
preg_match('/SID=(.+)/', $response['body'], $matches);
$sid = $matches[1];
// Erase POST variables used on the previous xhttp call
$data = array();
// Set the SID in cookies
$data['cookies'] = array(
'SID' => $sid
);
$response = xhttp::fetch('http://www.google.com/insights/search/overviewReport?q=lingerie&geo=ID&cmpt=q&content=1&export=1', $data);
// CSV data in the response body
echo $response['body'];
?>
The result is at: http://codecri.me/apps/test/test.google.trends.php
But I'm not sure if the result is what you are looking for.
Since April 2012 Google changed it's auth policy, edit the Arvin's code as follows:
// Extract Auth
preg_match('/Auth=(.+)/', $response['body'], $matches);
$auth = $matches[1];
// Erase POST variables used on the previous xhttp call
$data = array();
// Set the Authorization header
$data['headers'] = array(
'Authorization' => 'GoogleLogin auth='.$auth
);
The curl man page describes how to provide username and password. Have you tried the -u flag?
-u/--user
Specify the user name and password to use for server authentication. Overrides -n/--netrc and --netrc-optional.
If you just give the user name (without entering a colon) curl will prompt for a password.
If you use an SSPI-enabled curl binary and do NTLM authentication, you can force curl to pick up the user name and password from your environment by simply specifying a single colon with this option: "-u :".
If this option is used several times, the last one will be used.