I want to post an image on twitter but I can't. I am able to post only text message with twitter API.
The error is: Error: Server error: couldn't open file "Capture.png"
I use wamp server. The picture is in the same folder with the script.
Where is the problem?
require_once '../src/twitter.class.php';
// ENTER HERE YOUR CREDENTIALS (see readme.txt)
$twitter = new Twitter. ('raQBedybFLb', 'HWgN6Qt11jg0LY', '862846056-ndeGfMA83r9ldh', 'VMBvHDahXnGp');
$p='./Capture.png';
try {
$tweet = $twitter->send('testing twitter api', $p); // you can add $imagePath as second argument
} catch (TwitterException $e) {
echo 'Error: ' . $e->getMessage();
}
You may use $p = realpath('Capture.png');
Related
I use the Lists-WS from Sharepoint to retrieve information about DocumentLibraries and the files in these Libraries. Now I want to upload new files. How do I implement uploads with PHP? Till now I use Thybag SharePointAPI to get information (Link).
(the SharepointServer uses NTLM-Authentication)
THX in advance!!
UPDATE:
I want to call the Copy.asmx WS from sharepoint. To do so, I use the following lines:
$sourceurl = 'http://null';
$params = '
<CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SourceUrl>'.$sourceurl.'</SourceUrl>
<DestinationUrls>' . $destinationURLs . '</DestinationUrls>
<Stream>' . $stream . '</Stream>
</CopyIntoItems>
';
$xmlvar = new \SoapVar($params, XSD_ANYXML);
// Attempt to run operation
try {
$result = $this->soapClient->CopyIntoItems($xmlvar)->CopyIntoItemsResponse->CopyIntoItemsResult;
} catch (\SoapFault $fault) {
$this->onError($fault);
}
But I dont even get any response ($result == NULL).....
You can use SPServices' CopyIntoItems method. You can find a detailed conversation here containing the details on using the CopyIntoItems service to upload a document.
I'm creating a module for joomla that lists the the contents of a given folder. This module works as a service, so no OAuth should be required.
I'm stuck since every request I make has the same answer, no items. So I would like to know if I'm creating the client/service in a wrong way or I may have registered the application in a wrong way.
Here is the code:
// this class is where I have all the IDs from the google console
require_once(dirname(__FILE__) . '/gdrive/config.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/apiClient.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/contrib/apiDriveService.php');
$client = new apiClient();
$key = file_get_contents(Config::KEY_FILE);
$client->setClientId(Config::CLIENT_ID);
$client->setUseObjects(true);
$client->setAssertionCredentials(new apiAssertionCredentials(
Config::SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'), $key)
);
$service = new apiDriveService($client);
try {
$parameters = array();
$parameters['maxResults'] = $maxResults;
$files = $service->files->listFiles($parameters);
$items = $files->getItems();
var_dump($items);
$pageToken = $files->getNextPageToken();
} catch (apiServiceException $e) {
print "Error code :" . $e->getCode() . "\n";
// Error message is formatted as "Error calling <REQUEST METHOD> <REQUEST URL>: (<CODE>) <MESSAGE OR REASON>".
print "Error message: " . $e->getMessage() . "\n";
} catch (apiException $e) {
// Other error.
print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "\n";
} catch (Exception $e) {
print "Cannot retrieve the files";
print($e->getMessage());
}
Sorry to ask such a noob question but this is driving me crazy
Thanks
P.S. just for the record, I followed this google-api-php-client/wiki/OAuth2#Service_Accounts
After having a second look to the documentation I found that Google Drive does not support service accounts. I don't know if this is going to change but, with the requirements I have (I need to show in the web is what an end user uploads to a folder (which is public) using the desktop app) I think I cannot use google drive as a valid solution.
I found a solution but I don't like to much since I should have to refresh the token forever Google Drive SDK Service Account Error
I have a quiz application on Facebook. It uploads a photo to user's photos at the end of the quiz.
$photo_upload = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . './images/userimg.png',
'message' => $message,
)
);
But it is a sample image, the same for everyone. I want to make it personal by writing the user's name on the image. Part of create-img.php:
try {
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e) {
error_log($e);
$user_id = null; }
$username = iconv("UTF-8", "ISO-8859-2", $user_profile['name']);
$text = iconv("ISO-8859-2", "UTF-8", "Hello ". $username);
...
header('Content-type: image/png') ;
ImagePNG($image) ;
ImageDestroy($image) ;
imagepng($image, "./images/imgs_to_post/sample_userimg.png");
exit ;
It can be included in HTML, works fine, the image shows up with the user's name.
<img src="create-img.php" alt="" />
But when I try to put create-img.php as source in the API call above, i get an error.
Fatal error: Uncaught OAuthException: (#1) An unknown error occurred thrown in /home/mmdesign/public_html/.../php-sdk/base_facebook.php on line 1128
How can I put the result image of imagepng in the API call as source?
Thank you in advance.
But when I try to put create-img.php as source in the API call above, i get an error.
Of course, because that file contains PHP code, not image data. (If you think the PHP code is parsed at this point, you’re wrong.)
Write the image to HDD first, and then feed the API the path to that image.
Im working on connecting my website to connect to Google Adwords to create ads and campains depending up on the products in my site. I tried connecting by sending direct curl request and parse the received SOAP response. But that is too becoming complex for each request. So i tried using the PHP client library provided in Google Code. But none of the example is working correctly. I changed the user account details in auth.ini file but still on excecuting the example files it says
Failed to get authToken. Reason:
couldn't connect to host'.
I tried running the scripts in different servers but still getting the same error.
Following is the code to fetch all ads from Google adwords and this is a example file from Client library
$path = dirname(__FILE__) . '/../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the AdGroupAdService.
$adGroupAdService = $user->GetAdGroupAdService();
$adGroupId = (float) '01';
// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'AdGroupId', 'Status');
$selector->ordering = array(new OrderBy('Id', 'ASCENDING'));
// Create predicates.
$adGroupIdPredicate = new Predicate('AdGroupId', 'IN', array($adGroupId));
// By default disabled ads aren't returned by the selector. To return them
// include the DISABLED status in a predicate.
$statusPredicate =
new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));
$selector->predicates = array($adGroupIdPredicate, $statusPredicate);
// Get all ads.
$page = $adGroupAdService->get($selector);
// Display ads.
if (isset($page->entries)) {
foreach ($page->entries as $adGroupAd) {
printf("Ad with id '%s', type '%s', and status '%s' was found.\n",
$adGroupAd->ad->id, $adGroupAd->ad->AdType, $adGroupAd->status);
}
} else {
print "No ads were found.\n";
}
} catch (Exception $e) {
echo 'Inside catch exception';
print $e->getMessage();
}
and in the settings.ini file
DEFAULT_SERVER =
"https://adwords-sandbox.google.com"
; AUTH_SERVER = "<SERVER>"
In auth.ini file
My Google account's username and password are set correctly.
Can someone help me in getting this issue fixed.
Thanks
It's the AUTH_SERVER setting, not DEFAULT_SERVER, that indicates where authentication requests are being sent. This should be at the bottom of settings.ini but is normally commented out so that the default setting of https://www.google.com is used. You should check that AUTH_SERVER is commented out and that you can connect to https://www.google.com.
I am using gigya php sdk, It works well I am able to post to user's wall or profile using socialise.setStatus method but I am have problems when I try to use the publishuseraction method. I get an error Invalid request signature.
$method = "socialize.publishUserAction";
$request = new GSRequest($apiKey,$secretKey,$method);
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\", \"linkBack\":\"http://google.com\", \"mediaItems\":[{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
$request->setParam("userAction", $userAction);
$request->setParam("uid", $userUID);
$response = $request->send();
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
}
UPDATED AFTER USING $response->getLog()
apiMethod=socialize.publishUserAction
apiKey=correct_api_key
params={"userAction":{},uid":"MY_UID","format":"json","httpStatusCodes":"false"}
URL=http://socialize.gigya.com/socialize.publishUserAction postData=uid=urlencoded(MY_UID)&format=json&httpStatusCodes=false&apiKey=correct_api_key×tamp=1296229876&nonce=1.29622987636E%2B12&sig=HEdzy%2BzxetV8QvTDjdsdMWh0%2Fz8%3D
server= web504
I used both put method
$userAction = new GSDictionary();
$userAction->put("title", "This is my title");
$userAction->put("userMessage", "This is my user message");
$userAction->put("description", "This is my description");
$userAction->put("linkBack", "http://google.com");
$mediaItems = array();
$mediaItems[0] = new GSDictionary("{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}");
& JSON method
$userAction = new GSDictionary("{\"title\":\"This is my title\", \"userMessage\":\"This is a user message\", \"description\":\"This is a description\",
\"linkBack\":\"http://google.com\", \"mediaItems\":[ {\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}]}");
I get the same error. And User action is empty using both methods. I appreciate any help.
Thanks.
Try calling getLog() for a bit more information about the error:
if($response->getErrorCode()==0){
echo "Success";
} else {
echo ("Error: " . $response->getErrorMessage());
print "<pre>";
print_r($response->getLog());
print "</pre>";
}
Also, are you able to run getUserInfo w/ the SDK? This is a simple test that also requires a signature. Use the example on the PHP SDK page (about 1/2 way down).