youtube data API to rate the video - json

i followed the youtube data api to rate the video from the app. But i got "not found 404 error."
https://www.googleapis.com/youtube/v3/videos/rate?id=Z98hXV9GmzY&rating=like&access_token="+token+"&key=XXXXX
what is the right way to do that... Any help is appreciated. Thankyou
I'm using codename one platform for the app by the way..
Login gc = GoogleConnect.getInstance();
gc.setCallback(new LoginCallback() {
#Override
public void loginFailed(String errorMessage) {
Dialog.show("Error Logging In", "There was an error logging in: " + errorMessage, "OK", null);
}
#Override
public void loginSuccessful() {
Dialog.show("Logged In", "you are currently logged in ", "OK", null);
}
});
if (!gc.isUserLoggedIn()) {
gc.doLogin();
} else {
token = gc.getAccessToken().getToken();
}
});
findLikes(f).addActionListener((e) -> {
ConnectionRequest cr = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
super.readResponse(input);
}
#Override
protected void postResponse() {
super.postResponse();
}
};
cr.setPost(false);
cr.setUrl("https://www.googleapis.com/youtube/v3/videos/rate?id=" + videoId + "&rating=like&access_token="+token+"&key=XXXXX"); //this doesnt give anything... is it not the right way??
cr.setDuplicateSupported(true);
NetworkManager.getInstance().addToQueueAndWait(cr);
});

you can not directly rate from the url. you need to use full rating code to give rate.
Youtube API
because firstly google authenticate of your application then it allows you to give rate Not directly from the
Your link

First off please tell use what language you are using I cant figure it out exactly from your code.
Videos: rate Add a like or dislike rating to a video or remove a rating from a video.
POST https://www.googleapis.com/youtube/v3/videos/rate
Remember this call is a http post not a HTTP GET. Ie you cant just place it in a web browser.
example:
POST https://www.googleapis.com/youtube/v3/videos/rate?id=b_bJQgZdjzo&rating=like&oauth_token={YOUR_accessTOken}
I am pretty sure it is oauth_token you use not key or access_token.

Related

How To Create Test Facebook Ads || How to Get Android Advertisement ID (AAID) programmatically?

How to create Test Device to Facebook Ads >> To Create Test Device you need Enter a device ID (IDFA, AAID):
sometimes we need to get the android advertisement id AAID for android device, when we place google ads or Facebook ads to our Android app or any other functions we need to place the unique AAID for testing purpose.
For Kotlin code
Thread{
AdvertisingIdClient.getAdvertisingIdInfo(activity).id?.let {
Log.i("myId",it)
}
}.start()
The first Step, get AdvertisingIdClient
public class AdvertisingIdClient extends Object
Helper library for retrieval of advertising ID and related information such as the limit ad tracking setting.
It is intended that the advertising ID completely replace existing usage of other identifiers for ads purposes (such as use of ANDROID_ID in Settings.Secure) when Google Play Services is available. Cases, where Google Play Services is unavailable, are indicated by a GooglePlayServicesNotAvailableException being thrown by getAdvertisingIdInfo().
Code >>>
#SuppressLint("StaticFieldLeak")
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String token = null;
AdvertisingIdClient.Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
} catch (IOException | GooglePlayServicesRepairableException | GooglePlayServicesNotAv
// ...
MessageLog.setLogCat("DEVICE_ID",""+e);
}
String android_id = adInfo.getId();
MessageLog.setLogCat("DEVICE_ID",android_id);
return android_id;
}
#Override
protected void onPostExecute(String token) {
MessageLog.setLogCat("DEVICE_ID","DEVICE_ID Access token retrieved:" + token);
}
};
task.execute();
Open Your Logcate of android studio
you will get Result like it
2020-07-23 19:32:37.225 19041-19093/com.packagename.example I/DEVICE_ID :: 1aaf7707-22b5-4627-xxx-xxxxxxxx
2020-07-23 19:32:37.738 19041-19041/com.packagename.example I/DEVICE_ID :: DEVICE_ID Access token retrieved:1aaf7707-22b5-4627-xxx-xxxxxxxx
1aaf7707-22b5-4627-xxx-xxxxxxxx is your device ID
Second Step: Open your Facebook Monetization Manager
write your device id in a device ID (IDFA, AAID): EditText and Write Name Device like the image.
The following code snippet might help lot of you in current cases.
Add this method in your code:
fun getIdThread() {
var adInfo: AdvertisingIdClient.Info? = null
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(this)
} catch (e: IOException) {
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (e: GooglePlayServicesAvailabilityException) {
// Encountered a recoverable error connecting to Google Play services.
} catch (e: GooglePlayServicesNotAvailableException) {
// Google Play services is not available entirely.
}
val id: String = adInfo?.id.orEmpty()
val isLAT: Boolean = adInfo?.isLimitAdTrackingEnabled?.orFalse() == true
}
And call from separate thread as like below.
Thread{
getIdThread()
}.start()
This simple snippet will give you the AD ID. Even if the user resets the advertising ID.
Note: [Don't forget to declare ad ID permission in your manifest]

How to make my Apex class return or "run" a JSON? using APEX REST

I am using the following code to generate a JSON for a Salesforce custom object called Resource Booking. How can I "run" the file (or call responseJSON) so that when I input the custom URL (in the first comment) it jumps to a page similar to this example web page? https://www.googleapis.com/customsearch/v1?json
Here is my code:
#RestResource(urlMapping='/demo/createTask/*') //endpoint definition > {Salesforce Base URL}/services/apexrest/demo/createTask/
global class ResourceBookingTransfer {
public List<Resource_Booking__c> resourceBookingList{get; set;}
public ResourceBookingTransfer(ApexPages.StandardController controller) {
//getResourceBookingList();
}
#HttpGet //HttpGet request
global static responseWrapper getResourceBookingList() {
responseWrapper responseJSON = new responseWrapper(); //responseWrapper object for API response
responseJSON.message = 'Hello World';
return responseJSON; //return the JSON response
//resourceBookingList = Database.query('SELECT Booking_ID__c, Booking_Name__c, Start_Date_Time__c, End_Date_Time__c, Resource__c FROM Resource_Booking__c');
}
//wrapper class for the response to an API request
global class responseWrapper {
global String message {get;set;} //message string
//constructor
global responseWrapper() {
this.message = '';
}
}
}
To just test it - it might be simplest to use https://workbench.developerforce.com. There's "REST explorer" menu in there. Your code should be available under resource similar to /services/apexrest/demo/createTask.
Why that url? Read https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm
Once you're happy with this manual testing - you can try to do it from outside workbench. Workbench logs you in to SF and passed header with valid session id in the background. If you want to call your service from another website or mobile app - you need to perform login call first, get the session id and then run your code. There are several OAuth flows you can use to do this depending in what your app needs, maybe start with this one: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm

How to show custom error page in ServiceStack

I have read through Error Handling, ServiceStack_Succinctly.pdf, ServiceStack 4 Cookbook and various SO questions and am still unable to get the following working.
I want a way to show my own "pretty" error page for any exception that is thrown in any of my services. If any exception is thrown I want to take the user to a friendly page that shows the error message without any information that "mere mortals" won't understand.
Ideally I want this while maintaining typed responses on my service requests, i.e. not
public object Get(GetOrder request)
{
return new GetOrderResponse()
{
...
}
}
but rather
public GetOrderResponse Get(GetOrder request)
{
return new GetOrderResponse()
{
...
}
}
I'd appreciate guidance on how to get this working or an example where this is done.
Thanks.
Have a look at the options for Fallback Error Pages e.g. you can display an /oops.cshtml Razor page with:
public override void Configure(Container container)
{
Plugins.Add(new RazorFormat()); //Register ServiceStack.Razor Plugin
this.GlobalHtmlErrorHttpHandler = new RazorHandler("/oops"),
}
Or for more fine-grained control, use IAppHost.CustomHttpHandlers for specifying custom HttpHandlers to use with specific error status codes, e.g.:
public override void Configure(Container container)
{
this.CustomHttpHandlers[HttpStatusCode.NotFound] =
new RazorHandler("/notfound");
this.CustomHttpHandlers[HttpStatusCode.Unauthorized] =
new RazorHandler("/login");
}

WebSocketServlet: Send message to particular connection

I am trying implement a Websocket connection taking an example from here - https://gist.github.com/chitan/3063774.
This is a echo server.
My question is -
How can i take a message from a particular user and send it to another user instead of echoing to the same user.
I have searched a lot and most of the examples i have found are Echo examples.
In Java EE7, you can do that easily. Think about an simple example. If you write client.getBasicRemote().sendObject(message); in a method with #OnMessage annotation than it will be available only active client session.
#ServerEndpoint("/websocket")
public class ChatEndpoint {
#OnMessage
public void message(String message, Session client) throws IOException, EncodeException {
client.getBasicRemote().sendObject(message);
}
}
if you loop the message on client.getOpenSessions() then it will be available to all clients:
#OnMessage
public void message(String message, Session client) throws IOException, EncodeException {
for (Session peer : client.getOpenSessions()) {
peer.getBasicRemote().sendObject(message);
}
}
For details, go to this tutorial.
If you still need to use Java 6 and WebSocketServlet you can do something like this:
public class WsChatServlet extends WebSocketServlet{
public StreamInbound createWebSocketInbound(String protocol){
MyMessageInbound ms = new MyMessageInbound();
// store ms somewhere and than find it and use getWsOutbound() to respond
return ms;
}
...
}

GWT JsonpRequestBuilder Timeout issue

I am getting time out from using JsonpRequestBuilder.
The entry point code goes like this:
// private static final String SERVER_URL = "http://localhost:8094/data/view/";
private static final String SERVER_URL = "http://www.google.com/calendar/feeds/developer-calendar#google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true";
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* This is the entry point method.
*/
public void onModuleLoad() {
JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder();
// requestBuilder.setTimeout(10000);
requestBuilder.requestObject(SERVER_URL, new Jazz10RequestCallback());
}
class Jazz10RequestCallback implements AsyncCallback<Article> {
#Override
public void onFailure(Throwable caught) {
Window.alert("Failed to send the message: " + caught.getMessage());
}
#Override
public void onSuccess(Article result) {
// TODO Auto-generated method stub
Window.alert(result.toString());
}
The article class is simply:
import com.google.gwt.core.client.JavaScriptObject;
public class Article extends JavaScriptObject {
protected Article() {};
}
The gwt page, however, always hit the onFailure() callback and show this alert:
Failed to send the message. Timeout while calling <url>.
Fail to see anything on the Eclipse plugin console. I tried the url and it works perfectly.
Would appreciate any tip on debugging technique or suggestion
Maybe you should set the callback function explicitly via setCallbackParam, since you have callback=insertAgenda in your url - I presume that informs the server what should be the name of the callback function that wraps the JSON.
Also, it's worth checking Firebug's console (or a similar tool for your browser) - even if GWT doesn't report any exceptions, Firebug still might.
PS: It's useful to use a tool like Firebug to see if the application does in fact receive the response from the server (that would mean that, for example, you do need the setCallbackParam call) or maybe there's something wrong on the server side (for whatever reason).
You have to read the callback request-Parameter (default callback, value something like __gwt_jsonp__.P0.onSuccess) on serversite and have to modify the output to
<callback>(<json>);
In this case:
__gwt_jsonp__.P0.onSuccess(<json>);
Both of these guys are absolutely correct, but here is a concrete example to help you understand exactly what they are referring too.
This is a public JSON api. Take a look at the results:
http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4
This public API supports JSONP through the predefined parameter 'callback'. Basically whatever value you pass into callback, will be used as the function name to wrap around the JSON data you desire. Take a look at the results of these few requests:
http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4&callback=totallyMadeUp
http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4&callback=trollingWithJSONP
It could be happening because of another reason, that the webservice call is returning a JSON object and but the callback is expecting JSONP object (note there is a difference).
So if you are dealing with google maps api, and you are seeing this exception, you need to change it to api provide by maps api, something like
final GeocoderRequest request = GeocoderRequest.create();
request.setAddress(query);
try {
GWT.log("sending GeoCoderRequest");
if (m_geocoder == null) {
m_geocoder = Geocoder.create();
}
m_geocoder.geocode(request, new Geocoder.Callback() {
#Override
public void handle(final JsArray<GeocoderResult> results,
final GeocoderStatus status) {
handleSuccess(results, status);
}
});
} catch (final Exception ex) {
GWT.log("GeoCoder", ex);
}
Or else you could use RequestBuilder as in gwt library.