I am trying to create a video ad through Facebook Marketing API. And I stuck on uploading the video.
When I am doing the next:
ad_video = ad_account.advideos.create(
name: 'Tests video 1',
source: File.expand_path('../file_example_MP4_480_1_5MG.mp4')
)
I am getting this response:
FacebookAds::ClientError: Service temporarily unavailable: Error Uploading Video
Also, I was trying to make it with URL:
ad_video = ad_account.advideos.create(
name: 'Tests video 1',
title: 'Test',
description: 'Test',
file_url: 'https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'
)
No luck, same answer:
FacebookAds::ClientError: Service temporarily unavailable: Error Uploading Video
Please help, what am I doing wrong?
you can do it this way with php
function video_creat($token,$act_id,$video_url){
try {
$fb=fbconngrap(); $response = $fb->post(
'/'.$act_id.'/advideos',
array (
'file_url' => $video_url,
),$token);} catch(Facebook\Exceptions\FacebookResponseException $e) {echo 'Graph returned an error: ' . $e->getMessage();exit;}catch(Facebook\Exceptions\FacebookSDKException $e) {echo 'Facebook SDK returned an error: ' . $e->getMessage();exit;}$graphNode = $response>getGraphNode();}
Related
I want to obtain users' phone numbers via Google sign-in on my website. In JavaScript for the "sign in with Google" button, I'm including scope 'https://www.googleapis.com/auth/user.phonenumbers.read' for permission to read the user's phone number. Maybe instead of this scope, I need to use 'https://www.googleapis.com/auth/contacts.readonly'. In any case, how do I obtain a signed-in user's phone number in PHP or JavaScript? When a user clicks on the sign-in button then because of the scope Google does ask permission to share a phone number. In Google API Console -> Edit app registration -> Scopes, I've included this phone number scope. Also, I've enabled People API in the Google project. I've installed
composer require google/apiclient
From the front end i'm receiving id-token for the signed-in user. My PHP is:
<?php
require_once 'vendor/autoload.php';
$id_token = $_POST['idtoken'];
$client = new Google_Client(['client_id' => '349001386451-bpovja3t7soabdu3cbhnig12fqlr20o0.apps.googleusercontent.com']);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$userid = $payload['sub'];
echo "Userid: $userid";
} else {
echo "Invalid ID token";
}
( The above code has been edited from https://developers.google.com/identity/sign-in/web/backend-auth )
I'm a newbie to this. I've got my client-id, client-secret and user's id-token. I'm able to show the userid in the above code, how to display the phone number?
Edit: I downloaded my client_secret.json and tried another method:
index.php
<?php
require_once __DIR__.'/vendor/autoload.php';
session_start();
$client = new Google\Client();
$client->setAuthConfig('client_secret.json');
$client->setScopes(array('https://www.googleapis.com/auth/user.phonenumbers.read', 'https://www.googleapis.com/auth/contacts.readonly', 'profile'));
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_PeopleService( $client );
$optParams = ['personFields' => 'phoneNumbers'];
$profile = $service->people->get( 'people/me', $optParams );
var_export($profile);
var_export( $profile->getPhoneNumbers() );
} else {
$redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . '/testing/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
--
oauth2callback.php
<?php
require_once __DIR__.'/vendor/autoload.php';
session_start();
$client = new Google\Client();
$client->setAuthConfigFile('client_secret.json');
$client->setRedirectUri('https://' . $_SERVER['HTTP_HOST'] . '/testing/oauth2callback.php');
$client->addScope(Google_Service_PeopleService::USER_PHONENUMBERS_READ);
if (! isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . '/testing/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
But when I'm running index.php it's giving error:
"error": { "code": 403, "message": "The caller does not have
permission to request "people/me". Request requires one of the
following scopes: [profile]."
But I do have included the profile scope in index.php
The phone number used for password reset will not be possible access:
It has been determined that we will not return the account recovery
phone number. The account recovery phone number is only intended for
specific usage like recovery the account when locked out. In the
interest of protecting user privacy this will not be returned in the
3rd party API.
I'm successfully getting phone number using a new 3rd method as given here:
https://developers.google.com/people/api/rest/v1/people/get?apix=true&apix_params=%7B%22resourceName%22%3A%22people%2Fme%22%2C%22personFields%22%3A%22phoneNumbers%22%7D
I copied the JavaScript code given in this link, removed all scopes except one, replaced YOUR_API_KEY and YOUR_CLIENT_ID, ran it on my server, in Firefox and it worked!
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for people.people.get
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/user.phonenumbers.read"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("YOUR_API_KEY");
return gapi.client.load("https://people.googleapis.com/$discovery/rest?version=v1")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.people.people.get({
"resourceName": "people/me",
"personFields": "phoneNumbers"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
But it only reads the phone number(s) added in Google account's "About me": https://myaccount.google.com/profile
And not the phone number of Google account which is used for password reset. I actually want this number but don't know whether possible.
I was trying to send sms without opening sms app. I have tried expo sms but no luck. I have also tried few other packages but still nothing...is there a way?
Looks like this library is working fine and reached the goals to send a message without going into the default message environment.
var phoneNumbers = {
"addressList": ["+911212121212", "+911212121212"]
};
var message = "This is automated test message"
SmsAndroid.autoSend(
phoneNumbers,
message,
(fail) => {
console.log('Failed with this error: ' + fail);
},
(success) => {
console.log('SMS sent successfully');
},
);
You can use this module npm install react-native-sms --save && react-native link react-native-sms
Next step add some code:
import SendSMS from 'react-native-sms'
someFunction() {
SendSMS.send({
body: 'The default body of the SMS!',
recipients: ['0123456789', '9876543210'],
successTypes: ['sent', 'queued'],
allowAndroidSendWithoutReadPermission: true
}, (completed, cancelled, error) => {
console.log('SMS Callback: completed: ' + completed + ' cancelled: ' + cancelled + 'error: ' + error);
});
}
googleapis node.js library is returning the below error when trying to query cloud search API.
Error: Invalid JSON payload received. Unknown name \"requestOptions[searchApplicationId]\": Cannot bind query parameter. Field 'requestOptions[searchApplicationId]' could not be found in request message."
The payload is exactly as documented here, https://developers.google.com/cloud-search/docs/reference/rest/v1/query/search. requestOptions[searchApplicationId] is present and if I remove it I get an error saying searchApplicationId is required.
Code:
const {google} = require('googleapis');
const service = google.cloudsearch({version: 'v1'});
service.query.search({
auth: jwtClient,
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}).then((res) => {
console.log(JSON.stringify({results:res.results.length}));
console.log(JSON.stringify({resultsInfo:res.results[0]}));
}).catch((err) => {
console.error('Unexpected error with cloud search API.');
console.error(err.toString());
});
The query works from the API explorer.
https://developers.google.com/apis-explorer/#search/cloudsearch/m/cloudsearch/v1/cloudsearch.query.search?_h=1&resource=%257B%250A++%2522requestOptions%2522%253A+%250A++%257B%250A++++%2522searchApplicationId%2522%253A+%2522searchapplications%252Fdefault%2522%250A++%257D%252C%250A++%2522query%2522%253A+%2522Testing%2522%250A%257D&
Am I missing something simple? Is this an issue with Google's client library? (https://github.com/googleapis/google-api-nodejs-client) Any assistance would be greatly appreciated.
Finally figured it out. Had to wrap the request in a requestBody JSON.
service.query.search({
auth: jwtClient,
requestBody: {
requestOptions: {
searchApplicationId: 'searchapplications/default',
debugOptions:{enableDebugging: true}
},
query: 'My query'
}
})
I would like to read Google Docs and Google Sheets shared by users with a specific user (myapp) created by me for my application. I have implemented the Google hybrid server slide flow (offline access) yo use Google services on behalf of this user when he is offline.
I store the refresh token in my database and use it to refresh the access token. With the access token I can query the API. For example, the following code correctly returns the files on the "myapp" drive:
// Get the API client
$client = new Google_Client();
$client->setClientId($this->clientId);
$client->setClientSecret($this->clientSecret);
$client->setAccessType('offline');
...
$client->addScope([
'https://spreadsheets.google.com/feeds',
'https://docs.google.com/feeds',
Google_Service_Drive::DRIVE
]);
// Construct the service object
$service = new Google_Service_Drive($client);
$params = array(
'pageSize' => 10,
'fields' => "nextPageToken, files(id, name)"
);
$results = $service->files->listFiles($params);
foreach ($results->getFiles() as $file) {
printf("%s (%s)\n", $file->getName()); // OK
}
...works fine!
Some of the files are shared by other users to "myapp".
Now I would like to get content of a shared Spreadsheet:
$fileId = "1GRTldB2....";
$result = $service->files->get($fileId, [
'fields' => 'name,md5Checksum,size,createdTime,modifiedTime,ownedByMe,properties,shared,sharedWithMeTime,webContentLink,webViewLink'
]);
$url = $result['webViewLink'];
//$url = 'https://www.googleapis.com/drive/v3/files/'.$fileId.'?alt=media';
$method = 'GET';
$headers = ["Authorization" => "Bearer $accessToken", "GData-Version" => "3.0"];
$httpClient = new GuzzleHttp\Client(['headers' => $headers]);
$resp = $httpClient->request($method, $url);
$body = $resp->getBody()->getContents();
$code = $resp->getStatusCode();
$reason = $resp->getReasonPhrase();
echo "$code : $reason\n\n";
echo "$body\n";
This code gives an error:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException'
with message ' in
C:\wamp\www\core\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php
on line 107 ( ! ) GuzzleHttp\Exception\ClientException: Client error:
GET
https://www.googleapis.com/drive/v3/files/1GRTldB2KDFGmFZgFST28-MaHKs7y7eqelbzDpdxuJBg?alt=media
resulted in a 401 Unauthorized response: { "error": { "errors": [ {
"domain": "global", "reason": "authError", "message": "Invalid
Credentials" (truncated...) in
C:\wamp\www\core\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php
on line 107
authError / InvalidCredentials
Any ideas?
Is the Shared-Sheet ...being shared with the "user" that you are using on the Google api? You know when you right click on the actual document and say "Share..."
I have a project on building a shopify app through "embedded SDK" The app was installed successfully but it does not redirect back to admin where the app should show the API call result. When I try to access the app that I installed the frame will just display The server refused the connection.
I used the joshrps/laravel-shopify-API-wrapper for my laravel project. This is my controller where I make a request to install the app http://pastebin.com/zEn96SWs , this is my redirect uri when the app is successfully installed:
Route::get('shopify',function(){
$sh = App::make('ShopifyAPI',[
'API_KEY'=>'a1568bd534e2e7a88b21d693bdc73afe',
'API_SECRET'=>'b15f951478db59369da196e77ea23fb7',
'SHOP_DOMAIN'=>'shinobishop.myshopify.com']);
$code = Input::get('code');
try`enter code here`
{
$accessToken = $sh->getAccessToken($code);
}
catch (Exception $e)
{
echo '<pre>Error: ' . $e->getMessage() . '</pre>';
}
));
I hope you can help me with this issue. Its my first time using shopify API on projects.
I think you need this in your controller:
$authorize_url = $sh->installURL([
'permissions' => array (
'write_orders', 'write_products'
),
'redirect' => 'https://dev.yourshopifystore.com/route/'
]);
return Redirect::to($authorize_url);